Possible Duplicate:
MySql select format, round column
When i make a SQL query using the ROUND(X, D), where D is a column name rather than the direct integer value, the result is rounded fine, but has too many decimal digits.
For example,
SELECT b.digits, ROUND(a.amount, b.digits) as amount
FROM a
JOIN b
ON a.number_id = b.id
the result is something like this:
3 357.143000000000000000000000
2 89.290000000000000000000000
4 696.436600000000000000000000
2 214.290000000000000000000000
2 328.570000000000000000000000
2 437.500000000000000000000000
The column b.digits contains the digits to which the value must be rounded. It is possible to get the result based on the digits, like this:
3 357.143
2 89.29
4 696.4366
2 214.29
2 328.57
2 437.50
try with the
formatfunction:like this:
SELECT b.digits, FORMAT(a.amount, b.digits) as amountFROM a
JOIN b
ON a.number_id = b.id