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.
Related
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.
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.
Ive created a game and in that game played 5 users which collected few points, Ive gived gifts manually but for next games how can i split or make in excel to calculate number of gifts,
this is ok using number format with 0 decimal places, 6+1+1+1 = 9
but in cases like this:
1+6+1+1+1 = 10, how can I make that only 9 gifts results?
You should be comparing their percent (B2/SUM(B2:B6)) against each prize as it relates to the total prize (e.g. 1/9). Since you are comparing decimal numbers with another decimal number and expecting an integer (no. of prizes), you will be rounding either up or down depending on whether you are favoring a wider distribution of the prizes or favoring the top score.
Either way you are going to have to decide whether the lowest score should always receive a prize or if the highest score should benefit from the points awarded.
The three possible formulas to start with would be,
=MROUND(C2, 1/9)*9 ◄ closest to even distribution
=FLOOR(C2, 1/9)*9 ◄ favours wider prize distribution
=CEILING(C2, 1/9)*9 ◄ rewards highest awarded points
Fill down as necessary.
Now you have to either take the highest or lowest score and adjust that to compensate for rounding the division of decimal numbers to an integer. MROUND doesn't play well with SUMPRODUCT but these two may give you a solution that you can live with.
=FLOOR($C2, 1/9)*9-((SUMPRODUCT(FLOOR($C$2:$C$6, 1/9)*9)-9)*($C2=MAX($C$2:$C$6)))
=CEILING($C2, 1/9)*9-((SUMPRODUCT(CEILING($C$2:$C$6, 1/9)*9)-9)*($C2=MAX($C$2:$C$6)))
Fill down as necessary.
If the MROUND solution is best suited to your prize distribution model, use a helper column that can determine the MROUND returns and then adjust the high score according to the sum of the helper column without circular references.
I have a database which houses scaled integers, the longest being 10 digits long. I am attempting to convert these to decimal values in Excel, moving the decimal point left by 4 digits, i.e. dividing by 10000.
Given that these integers are currently under the 15-digit significant figure limit, and will remain so, is there a possibility that I can encounter rounding errors?
is there a possibility that I can encounter rounding errors?
Strictly speaking I think yes. For example:
but what may be significant is that the discrepancy as shown (all formatted the same, the smaller black ones created by formula, the red ones by difference of those immediately above) is in the tenth decimal place, so hopefully not a problem.
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...