I’m currently calculating ‘fizziness’ which is equal to volume * fizzyfactor / 100.
However, the values become very long floats. I want to round them to one decimal point.
When typecasting with numeric, it still has the same output. Why? How can I fix this ?
Here is my query:
create or replace view fizz(softdrink, store, fizziness)
as
select name, store, (volume * fizzyfactor/100)::decimal(5,1) as fizziness
2
Answers
Is there any reason you cant use the SQL Round() function?
if not you could use this query to round to exactly one decimal point
you can read more about the Round() function here:
https://www.postgresqltutorial.com/postgresql-math-functions/postgresql-round/
Please recheck your data base
See the example below working with
::decimal(5,1)
as expected; same result obtained withround