Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
number to string without dot or decimal

Subject: number to string without dot or decimal

From: Amaninder Saini

Date: 11 Nov, 2009 03:09:01

Message: 1 of 4

Hi
If i have a number, num = 1.2e-3, is there any way that when i convert it to string the dot does not show up. In other words how can i get 12e-4. I tried

sprintf('%2.0e', num) gives 1e-003
sprintf('%2.0f', num) gives 0
num2str(num) gives 0.0012
but i am looking for a string with no dot that is 12e-4.

Thanks in advance

Subject: number to string without dot or decimal

From: Naresh Pai

Date: 11 Nov, 2009 03:52:02

Message: 2 of 4

"Amaninder Saini" <prince2princeca@hotmail.com> wrote in message <hdd9sd$a5b$1@fred.mathworks.com>...
> Hi
> If i have a number, num = 1.2e-3, is there any way that when i convert it to string the dot does not show up. In other words how can i get 12e-4. I tried
>
> sprintf('%2.0e', num) gives 1e-003
> sprintf('%2.0f', num) gives 0
> num2str(num) gives 0.0012
> but i am looking for a string with no dot that is 12e-4.
>
> Thanks in advance

% Try:
 strrep(sprintf('%2.1e', num),'.','')

Subject: number to string without dot or decimal

From: arun

Date: 11 Nov, 2009 07:52:32

Message: 3 of 4

On Nov 11, 4:09 am, "Amaninder Saini" <prince2princ...@hotmail.com>
wrote:
> Hi
> If i have a number, num = 1.2e-3, is there any way that when i convert it to string the dot does not show up. In other words how can i get 12e-4. I tried
>
> sprintf('%2.0e', num) gives 1e-003
> sprintf('%2.0f', num) gives 0
> num2str(num)  gives  0.0012
> but i am looking for a string with no dot that is 12e-4.
>
> Thanks in advance

The documentation claims that the powers are written in multiples of
3. Probably, you will have to do it manually then.

The solution provided by Naresh will give 12e-3 and not 12e-4.

if your format always remains x.ye-3 then, you could do it this way.

num = 1.2e-3;
num = num/10;
num_c = num2str(num, '%10.1e\n');
num_c = strrep(num_c, '.', '');

best, arun.

Subject: number to string without dot or decimal

From: Amaninder Saini

Date: 11 Nov, 2009 16:44:03

Message: 4 of 4

arun <aragorn168b@gmail.com> wrote in message <175e1503-b9a8-466d-8179-03f1f8a617cf@v25g2000yqk.googlegroups.com>...
> On Nov 11, 4:09?am, "Amaninder Saini" <prince2princ...@hotmail.com>
> wrote:
> > Hi
> > If i have a number, num = 1.2e-3, is there any way that when i convert it to string the dot does not show up. In other words how can i get 12e-4. I tried
> >
> > sprintf('%2.0e', num) gives 1e-003
> > sprintf('%2.0f', num) gives 0
> > num2str(num) ?gives ?0.0012
> > but i am looking for a string with no dot that is 12e-4.
> >
> > Thanks in advance
>
> The documentation claims that the powers are written in multiples of
> 3. Probably, you will have to do it manually then.
>
> The solution provided by Naresh will give 12e-3 and not 12e-4.
>
> if your format always remains x.ye-3 then, you could do it this way.
>
> num = 1.2e-3;
> num = num/10;
> num_c = num2str(num, '%10.1e\n');
> num_c = strrep(num_c, '.', '');
>
> best, arun.
Thanks to all

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us