Reply to Re: reducing decimals

Your name:

Reply:


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
==================

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация