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