You are here: Re: how to stop variable rounding up after a division « PHP Programming Language « IT news, forums, messages
Re: how to stop variable rounding up after a division

Posted by Colin Fine on 10/08/06 10:59

Alvaro G. Vicario wrote:
> *** mantrid escribió/wrote (Sat, 07 Oct 2006 18:36:03 GMT):
>> $price=number_format($price/100,2);
>> $price=number_format($price,2)/100;
>
>> 80 becomese 1 instead of 0.8
>> 180 becomes 2 instead of 1.8
>
> In my system, this code:
>
> <?php
>
> echo number_format(80/100, 2) . "\n";
> echo number_format(80, 2)/100 . "\n";
>
> ?>
>
> prints this output:
>
> 0.80
> 0.8
>
> :-?
>
>
> You can try forcing a cast to float, that works in other languages:
>
> (float)$foo
> 100.0
>
>

That makes sense. The second example is not formatting the fraction, so
it is printed in default format.

Colin

 

Navigation:

[Reply to this 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

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