http://qs321.pair.com?node_id=97188


in reply to Re: Re: Re: Filthy Floats
in thread Filthy Floats

Perl 6 will have "big rats" that will represent 98/100 exactly. For now, you can use ints and do it yourself. Are you doing arithmetic on the value you fetch? I assume so, or it would not be converted from a string to a number. So, fetch the value, and use a regex to remove the decimal point and note how many digits were to the right of it originally. Now value X becomes (Y*Z) where Y is your integer and Z is the implicit power of ten. Do your math with Y, and also see what becomes of Z in the formulas but keep it implicit. When displaying stick the decimal in the string based on Z, but don't divide.

Replies are listed 'Best First'.
Re: Re: Re: Re: Re: Filthy Floats
by THuG (Beadle) on Jul 17, 2001 at 19:18 UTC

    Well, I'm getting the number from the DB, and then multiplying it against another number, modifying the other number. And then I'm displaying the number.

    It was treated as a number at some point in its history, even though I'm displaying it as a string and not really doing any math to it when I display it.

    Anyway, its all been resolved. At some point it is being converted to a single and Perl assumes those digits are significant. If I could pull the double from the DB and use it as a double I would be happy, but even if it is set as a double, it still becomes a single.