Reply to Re: reducing decimals

Your name:

Reply:


Posted by fssm2666 on 08/21/07 13:23

On Aug 20, 8:18 am, Jerry Stuckle <jstuck...@attglobal.net> wrote:
> 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.
> jstuck...@attglobal.net
> ==================- Hide quoted text -
>
> - Show quoted text -

Albert:

Try with the BCDIV() function, with 3 parameters: $number_1,$number_2
and $number_of_decimal

More information at....
http://cl.php.net/manual/en/ref.bc.php
http://cl.php.net/manual/en/function.bcdiv.php

Felipe Silva.

[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

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