Rounding off numbers in OpenOffice.org Calc

December 31st, 2007 by Bruce Byfield in

Your rating: None Average: 3.7 (7 votes)

For statistical and mathematical purposes, OpenOffice.org's Calc spreadsheet includes a variety of ways to round off numbers. If you're a programmer, you may also be familiar with some of these methods. However, you don't need to be a specialist to find some of these methods useful. You may want to round off for billing purposes, or because decimal places don't translate well into the physical world -- for instance, if the parts you need come in packages of 100, then the fact you only need 66 is irrelevant to you; you need to round up for ordering.. By learning the options for rounding, you can make your spreadsheets more immediately useful for you.

When you use a rounding function, you have two choices about how to set up your formulas. If you choose, you can nest a calculation within one of the rounding functions. For instance, the formula =ROUND((SUM(A1;A2)) adds the figures in cells A1 and A2, then rounds them off to the nearest whole number. But, even though you don't need to work with exact figures everyday, you may still want to refer to them occasionally. If that is the case, then you are probably better off separating the two functions, placing =SUM(A1;A2) in cell A3, and =ROUND (A3) in A4, and clearly labelling each function. Which choice you make for layout depends largely on your work habits; personally, I prefer the second, on the grounds that I may not remember the details of what I am doing if I look at the spreadsheet six months after I create it.

Rounding methods

The most basic function for rounding numbers in Calc is ROUND. This function will round off a number according to the usual rules of symmetric arithmetic rounding: a decimal place of .4 or less gets rounded down, while one of .5 or more gets rounded up. However, at times, you may not want to follow these rules. For instance, if you are one of those contractors who bills a full hour for any fragment of an hour you work, you would want to always round up so you didn't lose any money. Conversely, you might choose to round down to give a slight discount to a long-established customer. In these cases, you might prefer to use ROUNDUP or ROUNDDOWN, whose names, which, just as their names suggest, round a number to the nearest integer above or below it.

All three of these functions require the single argument of number -- the cell or number to be rounded. Used with only this argument, all three functions round to the nearest whole number, so that 46.5 would round to 47 with ROUND or ROUNDUP and 46 with ROUNDDOWN. However, if you use the optional count argument, you can specify the number of decimal places to include. For instance, if number was set to 1, then 48.65 would round to 48.7 with ROUND or ROUNDUP and to 48.6 with ROUNDDOWN.

As an alternative to ROUNDDOWN when working with decimals, you can use TRUNC, which -- unsurprisingly -- is short for "truncate." It takes exactly the same arguments as ROUNDDOWN, so which function you use is a matter of choice. If you aren't working with decimals, you might choose to use INT (short for "integer"), which takes only the number argument.

Another option is the ODD and EVEN pair of functions. ODD rounds up to the nearest odd number if what is entered in the number argument is a positive number, and rounds down if it is a negative number, while EVEN does the same for an even number.

Still another option are the CEILING and FLOOR functions. As you can guess from the names, CEILING rounds up and FLOOR rounds down. For both functions, the number that they round to is determined by the closest multiple of the number that you enter as the significance argument. For instance, if your business insurance is billed by the work week, the fact that you were only open three days one week would be irrelevant to your costs; you would still be charged for an entire week, and therefore might want to use CEILING in your monthly expenses. Conversely, if you are building customized computers and completed 4.5 in a day, your client would only be interested in the number ready to ship, so you might use FLOOR in a report of your progress.

Besides number and significance, both CEILING and FLOOR include an optional argument called mode, which takes a value of 0 or 1. If mode is set to 0, and both the number and the significance are negative numbers, then the result of either function is rounded up; if it is set to 1, and both the number and the significance are negative numbers, the the results are rounded down. In other words, if the number is -11 and the significance is -5, then the result is -10 when the mode is set to 0, but -15 when set to 1.

However, if you are exchanging spreadsheets between Calc and MS Excel, remember that the mode argument is not supported by Excel. If you want the answers to be consistent between the two spreadsheets, set the mode in Calc to -1.

A function somewhat similar to CEILING and FLOOR is MROUND. Like CEILING AND FLOOR, MROUND requires two arguments, although, somewhat confusingly, the second one is called multiple rather than significance, even though the two are identical. The difference between MROUND and CEILING and FLOOR is that MROUND rounds up or down using symmetric arithmetic rounding. For example, if the number is 77 and the multiple is 5, then MROUND gives a result of 75. However, if the multiple is changed to 7, then MROUND's result becomes 77.

Conclusion

Once you tease the various rounding functions out of Calc's long, undifferentiated list of functions, you can start to decide which is most useful for your purposes.

However, one last point is worth mentioning: If you are working with more than two decimal places, don't be surprised if you don't see the same number of decimal places on the spreadsheet as you do on the function wizard. If you don't, the reason is that Tools -> Options -> OpenOffice.org Cal -> Calculate -> Decimal Places defaults to 2. Change the number of decimal places, and, if necessary, uncheck the Precision as shown box on the same tab, and the spreadsheet will display as expected.

__________________________
--
Bruce Byfield (nanday)


Special Magazine Offer -- Free Gift with Subscription
Receive a free digital copy of Linux Journal's System Administration Special Edition as well as instant online access to current and past issues. CLICK HERE for offer

Linux Journal: delivering readers the advice and inspiration they need to get the most out of their Linux systems since 1994.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Anonymous's picture

Turn off rounding rumbers

On August 13th, 2009 Anonymous (not verified) says:

How would you turn off rounding numbers?

Calc seems to be rounding off numbers without me asking it to, while in
'Tools -> Options -> OpenOffice.org Cal -> Calculate -> Decimal Places' its at the default, 2.

My function is =QUOTIENT(POWER(QUOTIENT(D11;30);2);E11) but the result is always a whole number.

Not sure why... any help?

Anonymous's picture

Also, if you want to round

On March 29th, 2009 Anonymous (not verified) says:

Also, if you want to round to the nearest odd or even number, (which is useful if you have decimals and such) instead of rounding UP to the nearest odd or even number, you can do EVEN(ROUNDDOWN(#;0)) or ODD(ROUNDDOWN(#;0))

peter.green's picture

Correction to paragraph 4

On January 7th, 2008 peter.green says:

However, if you use the optional count argument, you can specify the number of decimal places to include. For instance, if number was set to 1, then 48.65 would round to 48.7 with ROUND or ROUNDUP and to 48.6 with ROUNDDOWN.

Shouldn't that read "...if count was set to 1..."?

Post new comment

Please note that comments may not appear immediately, so there is no need to repost your comment.
The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <pre> <ul> <ol> <li> <dl> <dt> <dd> <i> <b>
  • Lines and paragraphs break automatically.

More information about formatting options

Newsletter

Each week Linux Journal editors will tell you what's hot in the world of Linux. You will receive late breaking news, technical tips and tricks, and links to in-depth stories featured on www.linuxjournal.com.
Sign up for our Email Newsletter

Tech Tip Videos

From the Magazine

December 2009, #188

If last month's Infrastrucuture issue was too "big" for you then try on this month's Embedded issue. Find out how to use Player for programming mobile robots, build a humidity controller for your root cellar, find out how to reduce the boot time of your embedded system, and if you're new to embedded systems find out the basics that go into one. You can also read about the Beagle Board, the Mesh Potato and a spate of other interestingly named items. And along with our regular columns don't miss our new monthly column: Economy Size Geek.







Read this issue