如何在PHP中的浮点值末尾剪切不必要的零,例如:
3.0 --> 3
12.56300 --> 12.563
etc.
您可以只使用(double(或(float(而不使用(string(
echo (float)$input;
我发现一种简单的方法是:
$output = (double) (string) $input;
number_format($number, number of digits);
例如
echo number_format(2.222222, 2); //2.22