Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to round up to decimal place like money

I need to round money values up to the nearest cent, then do some operations on that rounded value. I cannot use Round() because this will also round down. These are all money values.

123.4567 --> 123.46
1.1349 --> 1.14

Is there any way to do this in SQL? If I need a UDF, please provide suggestion on how to accomplish code for that UDF.

EDIT: Data is stored as Float.

like image 603
MAW74656 Avatar asked Aug 31 '11 19:08

MAW74656


People also ask

Do you round up for money?

Rounding to the nearest dollar Round down for a dollar amount that has 0 to 49 cents. For example, $89.27 rounds down to $89. Round up for dollar amounts that have 50 to 99 cents. For example, $53.52 rounds up to $54.

How many decimal places is money rounded?

The US and Canadian dollar can't be transacted with more than 2 decimal places. When numbers represent money, we use rounding to replace an un-representable, un-transactable money amount with one that represents a cash tender.

What is 0.5 rounded up?

0.5 rounded off to the nearest whole number is 1. Since, the value after decimal is equal to 5, then the number is rounded up to the next whole number. Hence, the whole number of 0.5 will be 1.


2 Answers

CEILING(moneyvalue * 100) / 100

perhaps? Convert to pennies, round up to nearest whole penny, then convert back to dollars.

like image 96
Marc B Avatar answered Sep 27 '22 18:09

Marc B


Use Ceiling

select ceiling(1.1349 * 100) / 100

result is 1.14
like image 41
Adriano Carneiro Avatar answered Sep 27 '22 17:09

Adriano Carneiro