Remove BigDecimal from HighPrecisionMoney.fromPreciseAmount#443
Remove BigDecimal from HighPrecisionMoney.fromPreciseAmount#443benko-balog wants to merge 3 commits into
Conversation
| // Eg: 4 for 123.456 | ||
| val mostSignificantDigitOfFraction :: rest = fractionDigitsList | ||
|
|
||
| if (mostSignificantDigitOfFraction == 5 && rest.forall(_ == 0)) |
There was a problem hiding this comment.
I'm not sure where this number 5 is coming from. Can you explain?
There was a problem hiding this comment.
For the half even rounding we are interested in if we have exactly .5 in the fractional part. If it's lower or bigger it's down or up rounding, but if it's exactly something.5 we need to check for the integer's least significant digit (that's the next line in the code).
So this line is checking if the first digit after the decimal point is 5 and all the others are non-existent or zeros (to handle the cases of .50, .500, etc )
(Maybe firstDigitAfterDecimalPoint would be a better name for mostSignificantDigitOfFraction) 🤔
yanns
left a comment
There was a problem hiding this comment.
I'm just wondering if we are not optimizing too much.
I let you judge.
We can also look at https://github.com/JavaMoney/jsr354-ri-bp/blob/master/src/main/java/org/javamoney/moneta/FastMoney.java for some possible optimizations. The javadoc also mentions limitations.
|
For now, we are keeping this PR without merging to see if the previous changes were enough to improve the performance. |
|
@benko-balog Should we just close this for now and re-open if ever needed? |
Added 3 rounding algorithms to substitute the methods used on BigDecimal