All,

A long time ago I posted a question about an algorithm that converts
floating point/double values to strings.  I got one, but it does not work
all to well. I am using the float manager to convert strings to double.
That works perfectly.  Can someone suggest a recommended method for
converting doubles to strings?  I don't need the string in exponential
format, I just need the string to have 1 or 2 places precision.  An example
of the problem I am seeing is the following.

    User enters a number 1.2
    I convert that to a double using the float manager.  I get 1.2
    I multiply that by 1000 to get 1200.
    I store it in the database.
    I read it back out.
    Divide it by 1000 and get 1.2.

    In my double to string conversion I get the integer portion using the
following code.
    long iValue = ( long )1.2;    // Gives me a 1.
    I then subtract out the 1, i.e 1.2 - 1.0 to get .2
    I then multiply that by 10 and get 2.0  (at least that's what the
debugger says I have!);
    I then have the following code.
    long dValue = ( long )2.0;  // Gives me a 1.  <-- This is the problem

    I did not write this algorithm, I just used it!  Is there a better way
to do this?  The numbers I will need to convert will be in the following
range
    0.5 to 999.9.

Thanks,

Brad



-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palmos.com/dev/support/forums/

Reply via email to