Php奇怪的四舍五入

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. :)