Re: how to stop variable rounding up after a division
- From: Colin Fine <news@xxxxxxxxxxxxxxxxxxxx>
- Date: Sun, 08 Oct 2006 11:59:13 +0100
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
.
- References:
- how to stop variable rounding up after a division
- From: mantrid
- Re: how to stop variable rounding up after a division
- From: Alvaro G. Vicario
- how to stop variable rounding up after a division
- Prev by Date: Re: Creating Dynamic URLs
- Next by Date: Re: Forms and PHP
- Previous by thread: Re: how to stop variable rounding up after a division
- Next by thread: DOM XML Compile Problem
- Index(es):
Relevant Pages
|