|
Posted by Jerry Stuckle on 08/20/07 12:18
albert wrote:
>> Have a look at round()'s second parameter ...
>
> I tried this :
>
> $MyDec = 0.0024096385542168672344587321276776492595672607421875;
> $MyDecOk = round($MyDec, 4) ;
>
> The trouble is that this data is serialized in a text file afterward.
> Even with round($MyDec, 4), I do get 0.0023999999999... in the text file !
> I used the number_format function instead.
>
> albert
>
>
>
Yep, that's what happens with floating point numbers. Floating point is
stored in base 2, not base 10. 0.0024 in this format is a repeating
number (similar to 1/3 in decimal) and cannot be represented directly.
But now you're saying that you're storing the number in a text file -
which you didn't before. That's new information. Albert's comment is
right on with the original information you gave. With the new
information, number_format should work fine.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Navigation:
[Reply to this message]
|