I use postgresql 9.3
. When I round off whole numbers, I want to get results by suffixing .00.
SELECT ROUND(12345, 2) //Result:12345
How can I get a result like 12345.00
I found numeric formatting functions like TO_CHAR
can generate such a result.
SELECT TO_CHAR(ROUND(12345, 2), '99999D99') // 12345.00
Is there a way to get result in numeric data type itself?
No, you cannot and there is also no point. What you are after is a certain representation of a numeral and that is exactly what the
to_char()
function does. PG does not care about a.00
suffix, it's all bits on the inside anyway.However, if you want to work with an exact representation of a real number, you should use the
numeric
data type with the appropriate modifiers such as:Keep in mind though that the
numeric
data type is very slow compared to the other numeral types such asinteger
anddouble
.