开发者

Php weird rounding

Simple question: Why this behavior:

var_dump($calc_product);
var_dump($calc_price);
var_dump(round($calc_product,1));
var_dump(round($calc_price,1)开发者_运维技巧);

gives:

float(16.05) float(16.05) float(16) float(16.1)

Thanks!


Don't use floats for money.

A common method is to store the price in pence/cents, then to divide by 100 on display. This means you can use integer arithmetic instead, and avoids this issue.


Read

number_format and

money_format...

sure it will helps you. :)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜