开发者

Php weird rounding

开发者 https://www.devze.com 2023-03-03 15:22 出处:网络
Simple question: Why this behavior: var_dump($calc_product); var_dump($calc_price); var_dump(round($calc_product,1));

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

精彩评论

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