I have '9.999999999'::double precision
number and I want to convert it to decimal(8,2)
without any rounding. The result I am expecting is 9.99
. So far I tried:
select trunc('9.999'::double precision::numeric(8,3), 2)
and it works but I have to know number of precision digits for double precision value because if there will be more 9
then ::numeric(8,3)
will automatically round it to 10.000
.
What I can do about it?
Best Answer
Why not simply do the following?
This way you just truncate it, without assuming anything about the digits.
Notes:
numeric
- this is the type the parser interprets9.99999
, for example:That is, use an unlimited
numeric
in your example. This would accomodate all your digits.