+2  A: 

Are you sure that you are using the appropriate RoundingMode? RoundingMode 1 is ROUND_DOWN and RoundingMode 5 is ROUND_HALF_DOWN. Perhaps you are supposed to use ROUND_HALF_EVEN (which is common in some financial scenarios)?

Also, the code would be clearer if you used these enum constants instead of the RoundingMode.valueOf method.

Dan Dyer
yes learning in api...but im going to trade
roney tavares
+1 `ROUND_HALF_UP` is a possibility as well
barrowc
BASE=1077.70 - descount=16.17 totalvalue=1061.53 wrong with the table
roney tavares
ROUND_HALF_EVEN is also known as Banker's rounding.
Jonas Elfström
missing value of table! :(
roney tavares
A: 

You always run into questions about the exact rounding rules with problems like this.

Like, do we round before or after the subtraction. Also, you might say that as a shortcut, a 1.5% discount is the same as saying that we charge 98.5% of regular price, so we should just be able to multiply the original price by 98.5% and not have to do an extra subtraction. Right?

Suppose the price is 667.00.

Method 1: 667.00 * .015 = 10.005, round up to 10.01. Then 667.00 - 10.01 = 656.99.

Method 2: 667.00 * .015 = 10.005. 667.00 - 10.005 = 656.995. Round up to 657.00. Different answer.

Method 3: 667.00 * .985 = 656.995, round up to 657.00.

Also, Roney mentioned that the table is wrong for 1077.70. It's also wrong for 1280.55.

Jay
thanks jay.. As might be expected soon had to give a result and had to do in sql, but I would settle in as we have other java applications with the same problem: (
roney tavares
JAY!!!! i tri it...and work....but one dont work fineone value of table is missing '1280.55'subtotal=1261.34175BASE=1280.55 totalvalue=1261.34all the values are correct! only this no...someone in financial are wrong! 1261.34175 can't be rounded to 1261.35...by mathematical laws. im going to one reunion...the java WINS!!!! thanks very much!!!
roney tavares