Results 1 to 5 of 5

Math Help - Mathematica covert string to number problem - help

  1. #1
    Newbie
    Joined
    Jan 2010
    Posts
    3

    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?

    Thanks in advance!
    Last edited by CaptainBlack; January 7th 2010 at 11:13 PM.
    Follow Math Help Forum on Facebook and Google+

  2. #2
    Grand Panjandrum
    Joined
    Nov 2005
    From
    someplace
    Posts
    14,972
    Thanks
    4
    Quote Originally Posted by muiz View Post
    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?

    Thanks in advance!
    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
    Follow Math Help Forum on Facebook and Google+

  3. #3
    Newbie
    Joined
    Jan 2010
    Posts
    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?
    Follow Math Help Forum on Facebook and Google+

  4. #4
    Grand Panjandrum
    Joined
    Nov 2005
    From
    someplace
    Posts
    14,972
    Thanks
    4
    Quote Originally Posted by muiz View Post
    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
    Follow Math Help Forum on Facebook and Google+

  5. #5
    Newbie
    Joined
    Jan 2010
    Posts
    3
    Thanks, CB. I'm checking in help system.
    Follow Math Help Forum on Facebook and Google+

Similar Math Help Forum Discussions

  1. Question regarding covert multiple poles when calculating residues
    Posted in the Differential Geometry Forum
    Replies: 6
    Last Post: June 12th 2011, 11:53 AM
  2. Mathematica Problem
    Posted in the Math Software Forum
    Replies: 8
    Last Post: March 16th 2010, 12:00 PM
  3. Mathematica problem
    Posted in the Math Software Forum
    Replies: 2
    Last Post: December 16th 2009, 09:19 AM
  4. Replies: 3
    Last Post: November 23rd 2009, 05:40 AM
  5. the problem in mathematica
    Posted in the Math Software Forum
    Replies: 2
    Last Post: November 6th 2009, 01:25 PM

Search Tags


/mathhelpforum @mathhelpforum