Link to home
Start Free TrialLog in
Avatar of jpadkins49
jpadkins49

asked on

PostgreSQL Rounding

All,

I am in the process of creating a trigger in a PostgreSQL database. I need to round the decimal number to the nearest quarter. For instance, 14.68 would be rounded to 14.75. We have a time and attendance system that round items to time and a half. The problem is that when it rounds the total time calculated for overtime it rounds it to an odd decimal such as 14.68. Our company policies dictate that these items be rounded to the nearest quarter of a decimal. The easiest way to do this is on the database end rather than editing the source code of the project. I need a PostgreSQL function that rounds the numbers past the decimal to the nearest .25. Any help would be greatly appreciated.
Avatar of jpadkins49
jpadkins49

ASKER

I found the answer. The amounts are stored as epoch numbers within our PostgreSQL database. It does not look pretty, but here is what I got:
update accrual_balance set balance = cast(round((balance/60)/15.00)/4 as decimal(10,2))*60*60  where id = 8450

Let me know if there is an easier way.

Thanks
ASKER CERTIFIED SOLUTION
Avatar of cminear
cminear

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Avatar of earth man2
earth man2
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial