Get the whole part of a decimal number without rounding
Good morning.
I need Get the whole part of a decimal number without rounding.
I have this:
case when cast(f1 as integer)/3600<1 then '0'
when cast(f1as integer)/3600>=1 then
cast(f1 as integer)/3600 END
I try this:
case when truncate (cast(f1 as integer)/3600<1,1) then '0'
when truncate ( cast(f1 as integer)/3600>=1,1) then
truncate (cast (f1 as integer)/3600,1) END
But not is ok
Thanks.
0
Comments
Can you please add some example data for f1?
The CASE expression, to me, is not part of your question.
In Vertica,
::is the CAST operator. And casting leads to rounding. To get the integral part of a numeric with decimal fractions, I would use theFLOOR()function.Maybe the micro demo below sheds some light on what you're searching for.
Whatever you want to do with your CASE expression afterwards is up to you:
WITHnumerics(num) AS (SELECT 0.125UNION ALL SELECT 0.25UNION ALL SELECT 0.375UNION ALL SELECT 0.5UNION ALL SELECT 0.625UNION ALL SELECT 0.75UNION ALL SELECT 0.875UNION ALL SELECT 1)SELECTnum, num::INT, FLOOR(num)::INT, CEIL(num)::INTFROM numerics;num |num|FLOOR|CEIL0.125| 0| 0| 10.250| 0| 0| 10.375| 0| 0| 10.500| 1| 0| 10.625| 1| 0| 10.750| 1| 0| 10.875| 1| 0| 11.000| 1| 1| 1Hi!
Good Luck.
Thanks so much Solved