Written by Allen Wyatt (last updated November 16, 2024)
This tip applies to Excel 2007, 2010, 2013, 2016, 2019, Excel in Microsoft 365, and 2021
Greg needs to perform some integer divisions. It seems that Excel provides three functions that can be helpful: INT, TRUNC, and QUOTIENT. He's unclear, though, as to how these functions differ and which would be best for his purposes.
First, let's look at what the functions do. The INT function supposedly gives the integer portion of a value, though this doesn't exactly mean what you may think. What the function does is to return a rounded integer value, where the rounding is always toward the left on a number line. So, consider the following two formulas:
=INT(8/3) =INT(-8/3)
The difference between the two, of course, is that the dividend in the first is positive and in the second is negative. The result of the first formula is 2, and the result of the second is -3. This is because, again, INT always rounds toward the left on a number line.
The TRUNC function, on the other hand, always returns the integer portion of a value. So, it does no rounding; it simply chops off (truncates) everything after the decimal point. When both dividend and divisor are positive or negative values, TRUNC returns the same thing as INT. When the dividend and divisor have different signs, then they provide different results because TRUNC does no rounding, just "chopping."
Finally, the QUOTIENT function returns the same thing as the TRUNC function. The difference between the two is that TRUNC does the division to derive the parameter necessary for the truncation, and QUOTIENT uses two parameters, being the dividend and divisor. The following provide the same result and illustrate the difference in specifying values for the functions:
=TRUNC(8/3) =QUOTIENT(8,3)
There is one other thing that should be mentioned about the TRUNC function—it includes an option second parameter that allows you to indicate how many decimal places you want in the results. The default is 0, meaning it will return an integer value, as has been done in this tip so far. So, for integer division it is only suitable if you either leave off the second parameter or explicitly indicate that you want 0 digits after the decimal point:
=TRUNC(8/3) =TRUNC(8/3,0)
So, which should you use? The determining factor will be the nature of the data you are working with. If you are going to be using mixed negative and positive numbers—where the result of the division will be negative—then you are best to go with either TRUNC or QUOTIENT. If your data is all positive, then it doesn't really matter which one you use.
ExcelTips is your source for cost-effective Microsoft Excel training. This tip (13264) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, Excel in Microsoft 365, and 2021.
Create Custom Apps with VBA! Discover how to extend the capabilities of Office 2013 (Word, Excel, PowerPoint, Outlook, and Access) with VBA programming, using it for writing macros, automating Office applications, and creating custom applications. Check out Mastering VBA for Office 2013 today!
Programmers know that a staple of any language is the ability to create conditional statements. Excel understands this, ...
Discover MoreExcel includes a surprising number of functions you can use to round your data. Two such functions are FLOOR and CEILING, ...
Discover MoreExcel allows you to easily format cells with different fonts, borders, and colors. If you want to count the number of ...
Discover MoreFREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
There are currently no comments for this tip. (Be the first to leave your comment—just use the simple form above!)
Got a version of Excel that uses the ribbon interface (Excel 2007 or later)? This site is for you! If you use an earlier version of Excel, visit our ExcelTips site focusing on the menu interface.
FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
Copyright © 2024 Sharon Parq Associates, Inc.
Comments