Ответ 1
В PHP попробуйте number_format
:
$n = 1234.5678;
// Two decimal places, using '.' for the decimal separator
// and ',' for the thousands separator.
$formatted = number_format($n, 2, '.', ',');
// 1,234.57
Я хочу, чтобы реальные числа были, например, 12.92, но не 12.9241. Возможно ли это сделать?
В PHP попробуйте number_format
:
$n = 1234.5678;
// Two decimal places, using '.' for the decimal separator
// and ',' for the thousands separator.
$formatted = number_format($n, 2, '.', ',');
// 1,234.57
Для 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.1235
PHP: http://php.net/manual/en/function.number-format.php
$number = 1234.5678;
$formatted_number = number_format($number, 2, '.', '');
// 1234.56
Вы можете умножить свой номер на 100, выполнить округление результата, а затем разделить на 100.
Или в php используйте круглую функцию круглую функцию
$result=round(12.9241, 2);