-
-
Notifications
You must be signed in to change notification settings - Fork 101
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RoundedMoney. Incorrect result from method chain (multiply, divide) #304
Comments
Interesting, that's definitely a bug and is critical as for me. |
Let me add more clear test case. Put it into RoundedMoneyTest. @Test
public void testMultiplyDivideChain() {
// test that 1000 * 15 / 100 == 150
double multiplicand = 15.0;
MonetaryOperator ro = ScaleRoundedOperator.of(2, RoundingMode.HALF_UP);
RoundedMoney actual = RoundedMoney.of(1000.0, "USD", ro)
.multiply(multiplicand)
.divide(100);
BigDecimal expected = new BigDecimal("1000.00")
.multiply(BigDecimal.valueOf(multiplicand))
.divide(BigDecimal.valueOf(100), RoundingMode.HALF_EVEN);
assertEquals(actual, RoundedMoney.of(new BigDecimal("150.000"), "USD"));
assertEquals(actual.multiply(multiplicand).divide(100), RoundedMoney.of(expected, "USD"));
}
@Test
public void testMultiplyScaledBigDecimal() {
BigDecimal num = new BigDecimal("15000");// "15000" intCompact = 15000 scale = 0 precision = 5
System.out.println(num); //> "15000"
System.out.println(num.toPlainString()); //> "15000"
BigDecimal divisor = new BigDecimal("100");
BigDecimal dec = num.divide(divisor, RoundingMode.HALF_UP);
System.out.println(dec); //> "150" OK
num = new BigDecimal("15000").setScale(-3); // "1.5+4" intComp = 15 scale -3 precision = 2
System.out.println(num); //> "1.5E+4"
System.out.println(num.toPlainString()); //> "15000"
divisor = new BigDecimal("100");
dec = num.divide(divisor, RoundingMode.HALF_UP);
System.out.println(dec); //> "0E+3" WTF?
} So inside of |
I've come to the conclusion that it is the scale too but since JSR-354 wording is not restrictive on this I haven't pointed that out
Note that for
|
ok, I don't have a time to fix it but if you @artbasov can send us PR that would be great.
Maybe this will create a RoundMoney instance with a proper scale. Not sure if it will works |
Is @artbasov a JCP Member at least Associate or could he become one? We'd be happy to consider him and others as Contributors to JSR 354 if you want to. |
Please remind me: we can't accept PRs from not a JCP members? |
It seems that we are getting
Input: I would reevaluate the need to do |
@stokito In the RI and API we should not have IP contributions from a non-JCP member. Eclipse Foundation has similar requirements if you want to contribute to Jakarta EE now. A single line of code could be tolerable, but if your contribution is all over the place, you should sign at least the Associate Agreement (which is no different from those at Apache or Eclipse). Apache won't let you touch any code without that to even start with, ask @atsticks. |
I am a JCP member can I contribute? |
Yes, although we already proposed MR1 of the JSR, but if you have a PR or similar fix for a problem, we can always release 1.4.1 after that. |
I've created a small test which is failing in current
master/HEAD
and in 1.3 version forRoundedMoney
but passing forMoney
(if adopted)Is this an intended behavior and if so, is there a way to get the expected result in some other way with
RoundedMoney
?This issue might repeat the last case from #277 but uses different public API
The text was updated successfully, but these errors were encountered: