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 Alvaro G. Vicario on 10/07/06 19:16

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


--
-+ http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
++ Mi sitio sobre programación web: http://bits.demogracia.com
+- Mi web de humor con rayos UVA: http://www.demogracia.com
--

 

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

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