# Thread: Mathematica covert string to number problem - help

1. ## Mathematica covert string to number problem - help

Dear all, now I'm study mathematica, and face a problem like this:

I want to covert string "1107.302" to a double number and then do some calculation.

Code:
a = "1107.302 ";
Print[a];                 >> Output is 1107.302
b=ToExpression[a];
Print[b];                 >> Output is 1107.3
c = b * 2;
.......
But the ToExpression function lost the number "02", then what can I do? Any suggestions?

2. Originally Posted by muiz
Dear all, now I'm study mathematica, and face a problem like this:

I want to covert string "1107.302" to a double number and then do some calculation.

Code:
a = "1107.302 ";
Print[a];                 >> Output is 1107.302
b=ToExpression[a];
Print[b];                 >> Output is 1107.3
c = b * 2;
.......
But the ToExpression function lost the number "02", then what can I do? Any suggestions?

It is always a good idea to tell us what package/language you are using.

Check default format for the display of numerical data (instead of Print[b] try Print[(b-1107)*1000] )

CB

3. Thanks very much, CB!

I just new a noteBook and type the following codes:

Code:
a = "1107.302 ";
b = ToExpression[a];
Print[b - 1107];         >> Out put:  0.302 , this is correct
Print[b];                   >> Out put:  1107.3
Then I want to export the b's value to a temp file, I hope the value should be 1107.302, but actually, it's 1107.3.

What can I do then?

4. Originally Posted by muiz
Thanks very much, CB!

I just new a noteBook and type the following codes:

Code:
a = "1107.302 ";
b = ToExpression[a];
Print[b - 1107];         >> Out put:  0.302 , this is correct
Print[b];                   >> Out put:  1107.3
Then I want to export the b's value to a temp file, I hope the value should be 1107.302, but actually, it's 1107.3.

What can I do then?
The value is correct, change the format to something that will show a field width of 10 digits with three after the decimal point. I can't tell you how to do that because I don't run Mathematica, but it will tell you somewhere in the help system.

CB

5. Thanks, CB. I'm checking in help system.