我希望实数是例如12.92,但不是12.9241。有可能这样做吗?
发布于 2010-01-03 02:48:29
在PHP中,试试
$n = 1234.5678;
// Two decimal places, using '.' for the decimal separator
// and ',' for the thousands separator.
$formatted = number_format($n, 2, '.', ',');
// 1,234.57发布于 2010-01-03 02:51:37
对于PHP你可以使用number_format(),对于MySQL你可以使用FORMAT()函数。
MySQL:http://dev.mysql.com/doc/refman/5.1/en/string-functions.html#function_format
FORMAT(number, 2)示例:
mysql> SELECT FORMAT(12332.123456, 4);
-> '12,332.1235PHP:http://php.net/manual/en/function.number-format.php
$number = 1234.5678;
$formatted_number = number_format($number, 2, '.', '');
// 1234.56发布于 2018-10-03 02:32:47
$number = 1234.5678;
$teX = explode('.', $number);
if(isset($teX[1])){
$de = substr($teX[1], 0, 2);
$final = $teX[0].'.'.$de;
$final = (float) $final;
}else{
$final = $number;
}期末考试将是1234.56
https://stackoverflow.com/questions/1992406
复制相似问题