converting String to number?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

converting String to number?

Adam Cliffe
Hi,

I'm trying to extract some information from an XML file. I can get the
part I want as a string
but I'd like to convert it to a number so I can use it later.


Here's an example

        XMLtext="Variant=0.03140118509446um";

        step=substring(XMLtext,8,24);

        output=parseFloat(step);
        print(output,"should be",step);

        storage=newArray(1);
        storage[0]= output;


So using parseFloat I end up with 0.314

does anyone know of a way to increase the number of decimal places?
(or a better way of doing this?)

thanks

Adam




Dr Adam Cliffe
Research Scientist, Rorth Lab

Institute of Molecular and Cell Biology
61 Biopolis Drive
Proteos
Singapore 138673

tel: +65 6586 9731









Note: This message may contain confidential information. If this Email/Fax has been sent to you by mistake, please notify the sender and delete it immediately. Thank you.
Reply | Threaded
Open this post in threaded view
|

Re: converting String to number?

Michael Schmid
Hi Adam,

the number is ok and has full precision; only the output is formatted  
by displaying it with the number of digits given in Analyze>Set  
Measurements.

Add this to your macro:
   print(d2s(output, 9),"should be",step);
   print("further digits:",(output-0.0314));
It shows that you have about 16 digits of accuracy.

Note that double(float)-to-String conversion with d2s gives you a  
maximum of 9 digits behind the decimal point, d2s(output, 16)  
produces the same output as d2s(output, 9).

Michael
________________________________________________________________


On 21 Oct 2009, at 10:27, Adam Cliffe wrote:

> Hi,
>
> I'm trying to extract some information from an XML file. I can get the
> part I want as a string
> but I'd like to convert it to a number so I can use it later.
>
>
> Here's an example
>
>        XMLtext="Variant=0.03140118509446um";
>
>        step=substring(XMLtext,8,24);
>
>        output=parseFloat(step);
>        print(output,"should be",step);
>
>        storage=newArray(1);
>        storage[0]= output;
>
>
> So using parseFloat I end up with 0.314
>
> does anyone know of a way to increase the number of decimal places?
> (or a better way of doing this?)
>
> thanks
>
> Adam
>
>
>
>
> Dr Adam Cliffe
> Research Scientist, Rorth Lab
>
> Institute of Molecular and Cell Biology
> 61 Biopolis Drive
> Proteos
> Singapore 138673
>
> tel: +65 6586 9731
>
>
>
>
>
>
>
>
>
> Note: This message may contain confidential information. If this  
> Email/Fax has been sent to you by mistake, please notify the sender  
> and delete it immediately. Thank you.