Rounding in Excel - excel

So I've been tackling this rounding issue for the past month. I like to think I am competent but this problem has me rethinking my entire existence.
So here it is.
I have a volume and a rate.
Line 1 = 410496.15 X .044370 = 18213.89
Line 2 = 7146.09 X .043753 = 312.67
Because of rounding I get 18526.55 for the total instead of 18526.56 which is what I want.
Problem is if I round to the 2nd place line 2's total show 312.66 because its not rounding .665 up.
Basically they want me to round to the 4th place but display 2 digits. i.e 4.1545 = 4.16 and 4.1544 = 4.15
Am I making sense? Because I'm beginning to question reality here.

I think this is what you want:
=ROUND(ROUND(ROUND(value, 4), 3), 2)
You can't display this (wrong) rounding result but keep the right number without some programming. You can have two columns however with these two different numbers...
The "right" way of working with data is never rounding anything at all. You never need to - you can always display 2 decimal places for convenience keeping the precise number behind the scenes...

Related

Excel rounds up number in one record, rounds down the same number in another

Excel is rounding numbers inconsistently that is causing me issues. When using ROUND(), sometimes it rounds a specific number up, while at other times it rounds the same value down.
I've tried setting Excel to show exact values in settings, but it doesn't change anything.
This is an example of what is happening.
This is the simple formula ROUND((A1-B1)/2,4)
For one record I have the values (.3159 - .3152) which evaluate to .0007 then divide by 2 to get .00035.
For the next record I have the values (.3554 - .3547) which also evaluates to .0007 and divided by 2 results in .00035
So, even though both values are .00035 when I round off to 4 decimal places I am getting .0003 for one and .0004 for another. Same number, rounding to the same number of places, two different results. How can I fix this?
This is an issue with floating point numbers that is inherent and cannot be solved, only avoided.
Try these tests in Excel:
=(0,3159-0,3152)=(0,3554-0,3547) gives you FALSE.
=(0,3159-0,3152)-(0,3554-0,3547) gives you something like 5.55112E-17.
If you cannot accept the differences, you should round already in the middle of the calculation, not only at the end:
=ROUND(0.3159-0.3152,4)=ROUND(0.3554-0.3547,4) is TRUE
=ROUND(0.3159-0.3152,4)-ROUND(0.3554-0.3547,4) is 0
further reading: Is floating point arithmetic stable? and Binary floating point and .NET, by highly regarded Jon Skeet.

Excel: Add number before multiplying with PRODUCT(...)

I am calculating the geometric mean of a row in MS Excel by using the GEOMEAN(...) command.
What is the geometric mean: The row could be A1:A10. A geometric mean with
GEOMEAN(A1:A10)
is the product of all 10 cell values (multiplied together) after which the 10th root is taken (mathematically: nth_root(A_1 x A_2 x ... x A_n) ).
The issue: The command GEOMEAN(A1:A10) works fine as long as no cells contain negative values (actually just as long as the product ends up positive). If one cell has a negative value, then taking the root is mathematically an invalid action and Excel gives an error.
The solution: I can work-around this by adding a large enough number such as +1000000 to each value before doing GEOMEAN(A1:A10) and afterwards subtracting -1000000 from the result. This is a mathematical approximation to the pure geometrical mean.
The question: But how do I add +1000000 to each value in Excel? A solution would be to create a whole new extra row where the number is added, and then doing GEOMEAN on this row and subtracting the number from the result. But I would really like to avoid creating a new row, since I have many long data sets to perform this command on.
Is there a way to add the number inside the command itself? To add it onto each value before it is multiplied? Something along the lines of:
GEOMEAN(A1:A10+1000000)-1000000
Solution to avoid the work-around
Based on the answer from and discussion with #ImaginaryHuman072889
It turns out that a working command that avoids any work-around is:
IFERROR(GEOMEAN(A1:A10);-GEOMEAN(ABS(A1:A10)))
If an error are cought by the IFERROR, then we know that a negative result would have appeared, so this is constructed manually in that case.
BUT: This does not take into account the case mentioned by #ImaginaryHuman072889, though, because Excel seems to forbid any negative numbers involved and not just if the inner product is negative. For example, both GEOMEAN(-2,-2) as well as GEOMEAN(-2,-2,-2) give errors in Excel, even though they both should be mathematically valid, giving the results 2 and -2, respectively. To overcome this Excel-issue, we can simply write out the exact same command line manually:
IFERROR(PRODUCT(A1:A10)^(1/COUNTA(A1:A10));-(PRODUCT(ABS(A1:A10))^(1/COUNTA(A1:A10)))))
I add this solution to aid any by-comers who have the same issue. This mathematically works, but the fact that -2 and -2 have the geometrical mean 2 does seem a bit odd and not at all like any useful value of a "mean". It is still mathematically legal as far as I can find (WolframAlpha has no issue with it and the Wikipedia article never mentions a sign).
Your "workaround" of doing this:
GEOMEAN(A1:A10+1000000)-1000000
Is completely wrong. This is absolutely not equal to GEOMEAN(A1:A10).
Simple counter-example:
GEOMEAN({2,8}) returns the value of 4, which is the geometric mean of 2 and 8.
GEOMEAN({2,8}+1)-1 is equal to GEOMEAN({3,9})-1 which is approximately 4.196.
What is a valid workaround is if you multiply each value inside GEOMEAN by a certain value, then divide the result by that value.
Simple example:
GEOMEAN({2,8}*3)/3 is equal to GEOMEAN({6,24})/3 which is 4.
However, this method of multiplying by a constant does not help your situation, since this won't get rid of negative values.
Mathematically speaking, the geometric mean of a positive number and a negative number is an imaginary number, which is presumably why Excel cannot handle it.
Example:
2*-8 = -16
sqrt(-16) = 4i
Therefore, 4i is the geometric mean of 2 and -8. Notice how it has the same magnitude as GEOMEAN({2,8}), just that it is an imaginary number.
All that said... here is what I recommend you doing:
I suggest you return two results, one result is the magnitude of the geometric mean and the other is the phase of the geometric mean.
Formula for magnitude:
= GEOMEAN(ABS(A1:A10))
(Note, this is an array formula, so you'd have to press Ctrl+Shift+Enter instead of just Enter after typing this formula.) The use of ABS converts all negative numbers to positive before the GEOMEAN calculation, guaranteeing a positive geometric mean.
Formula for phase, I would just do something like this:
= IF(PRODUCT(A1:A10)>=0,"Real","Imaginary")
Which obviously returns Real if the geometric mean is a real number and returns Imaginary if the geometric mean is an imaginary number.
EDIT
Technically speaking, some of what I said wasn't completely precise, although the magnitude formula above still stands.
Some things I want to clarify:
If PRODUCT(data) is positive (or zero), then the geometric mean of data is positive (or zero).
If PRODUCT(data) is negative and if the number of entries in data is odd, then the geometric mean of data is negative (but still real).
If PRODUCT(data) is negative and if the number of entries in data is even, then the geometric mean of data is imaginary.
That said... if you want these formulas to be a bit more technically accurate, I would modify to this:
Adjusted formula for magnitude:
= GEOMEAN(ABS(A1:A10))*IF(AND(PRODUCT(A1:A10)<0,MOD(COUNT(A1:A10),2)=1),-1,1)
Adjusted formula for phase:
= IF(AND(PRODUCT(A1:A10)<0,MOD(COUNT(A1:A10),2)=0),"Imaginary","Real")
If the geometric mean is real, it returns the precise geometric mean (whether it is positive or negative), and if the geometric mean is imaginary, it returns a positive real value with the correct magnitude.
So, I just found the answer - although I have no idea why this works.
Doing GEOMEAN(A1:A10+1000000)-1000000 is actually possible. But by pressing enter and error #VALUE is displayed. You must click control+shift+enter to have the actual result displayed.
According to this: https://www.mrexcel.com/forum/excel-questions/264366-calculating-geometric-mean-some-negative-values.html
If anyone has an explanation for this, I am very interested.

Understanding ROUND() function in Excel/Libre Calc

I have recently discovered a weired behaviour of MS Excel as well as Libre Office Calc. When I rounded the following number directly to 1 decimal place (last column), it rounded differently than if I went to two decimal places first (2nd column) and then to one decimal place (3rd column).
number ROUND(A1,2) ROUND(A2,1) ROUND(A1,1)
4.449331525248 4.45 4.50 4.40
I'm not a mathematician, but in my sense the rounding directly to one decimal place (last column) is wrong.
Other numbers this happens to include [3.34690622103941, 4.14677866251134, 3.64939941850228, ...].
Can someone explain this phenomenon to me? Thanks!
(Please move this question to an appropriate community, if necessary)
Your results are different because the function looks at different parts of the number to complete either two or one decimal place for its starting point.
For 2dp it looks at 4.449 which is correctly rounded to 4.45, which then correctly rounds to 1dp as 4.5. This is then an incorrect result for 1dp compared to the original source number due to the extra step and the 9.
The moral is if you need 1dp then do it in one step only 4.449 rounds to 4.4. Based on below 5 goes down, above goes up.

Rounding in an amortization table

I'm currently writing a C program that among other things generates and prints out an amortization table with numbers rounded to two digits. I get the correct numbers everywhere, that is: monthly_payment = principal_paid + interest_paid except in the last row (last payment) where occasionally my results don't add up, and off by one. For example:
MonthlyPay: 88.83, PrinPaid: 87.96, IntPaid: 0.88
Of course looking at the results printed to 6 digits it's easy to see why this is happening:
MonthlyPay: 88.834637, PrincPaid: 87.955087, IntPaid: 0.879551
What's the best way to handle a situation like this?
What do financial institutions do?
There is no standard.
There are those who say, "Once you round, use the rounded value for all further totals."
There are others who disagree, saying that you should sum the unrounded values to avoid accumulated rounding error. For example, 0.0666 + 0.0666 + 0.0666 + ... 15 times should approximately equal 1.0000, but if rounding each term to 2 decimal places before summing, ends up being 0.07 * 15 = 1.05! So that's the argument for using unrounded values. Your off-by-one is only off-by-one because you have just two terms you're summing.
I think ultimately you have to consider the pros and cons of each method. Who would be interested in the rounding errors? Just the programmers? Accounting? Customers? How does it affect those people? And can you issue a statement that clears the ambiguity, like "Values displayed to 2 decimal places." in which case you don't round anything at all, but simply display the first two decimal places everywhere.
Don't round in your calculations. Round only when displaying to end users.
The displayed values might be off by a cent here or there (maybe, but I doubt it). But if you round in your calculations, you'll end up with either total underreporting interest paid and overreporting principal paid, or vice versa.
If you don't round, your calculations will be correct enough that they won't make 1 cent of a difference unless you do massive loan values.

Excel roundings not summing properly

I have a excel sheet with a few formulas like this:
A1,A2,A3= 0.13,1.25,2.21
A4: =(A1*A2) =0.16 ( 2 decimal points)
A5: =(A2*A3) =2.76 ( 2 decimal points)
A6: =SUM(A4;A5) =2.93 ( 2 decimal points )
And i want to show 0.16+2.76=2.92
well, there's my problem in bold. i want to add the values from the cells, not the formuls result. How can i do that ? Thank you
Presumably you're working with money which is why you need this.
One way to resolve this is to use =ROUND(A1*A2, 2) etc. and base your subsequent calculations from that.
Do be aware though that you will still occasionally get spurious results due to Excel using a 64 bit IEEE754 floating point double to represent numbers. (Although it does have some extremely clever circumvention techniques - see how it evaluates 1/3 + 1/3 + 1/3 - it will not resolve every possible oddity). If you're building an accounting-style sheet you are best off working in pence, and dividing the final result.
Round the values before you sum, ie:
=ROUND(A1*A2,2)
=ROUND(A2*A3,2)
You could wrap your formulas with the ROUND function:
=ROUND(A1*A2,2)
This will give you 0.16 as opposed to 0.163. Do this for each of your calculations and you'll only be calculating everything to two decimal places. Although I'm not sure why you'd want to do that.

Resources