tags:

views:

79

answers:

3

I want that real numbers would be for example 12.92, but not 12.9241. Is it possible to do like that?

+1  A: 

In PHP, try 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
John Feminella
+3  A: 

For PHP you can use number_format(), for MySQL use the FORMAT() function.

MySQL: http://dev.mysql.com/doc/refman/5.1/en/string-functions.html#function_format

FORMAT(number, 2)

Example:

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
Clash
You can also use ROUND() in the same fashion if you don't want the thousands delimiter.
Jordan
A: 

You can multiply your number by 100, do a rounding of the result and then divide back by 100.

Or in php use the round function round function

$result=round(12.9241, 2);
Patrick