Skip to content

Remove BigDecimal from HighPrecisionMoney.fromPreciseAmount#443

Open
benko-balog wants to merge 3 commits into
mainfrom
remove_bigdecimal_from_fromPreciseAmount
Open

Remove BigDecimal from HighPrecisionMoney.fromPreciseAmount#443
benko-balog wants to merge 3 commits into
mainfrom
remove_bigdecimal_from_fromPreciseAmount

Conversation

@benko-balog

@benko-balog benko-balog commented Oct 13, 2022

Copy link
Copy Markdown
Contributor

Added 3 rounding algorithms to substitute the methods used on BigDecimal

Comment thread util/src/main/scala/Money.scala
Comment thread util/src/test/scala/MoneyRoundingSpec.scala
Comment thread util/src/test/scala/MoneyRoundingSpec.scala Outdated
@benko-balog benko-balog marked this pull request as ready for review October 13, 2022 12:59
@benko-balog benko-balog requested a review from yanns as a code owner October 13, 2022 12:59

@clemniem clemniem left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

// Eg: 4 for 123.456
val mostSignificantDigitOfFraction :: rest = fractionDigitsList

if (mostSignificantDigitOfFraction == 5 && rest.forall(_ == 0))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure where this number 5 is coming from. Can you explain?

@benko-balog benko-balog Oct 13, 2022

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 yanns left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@benko-balog

Copy link
Copy Markdown
Contributor Author

For now, we are keeping this PR without merging to see if the previous changes were enough to improve the performance.
We are checking if there are more tests we could add, to make sure roundings are working correctly.

@clemniem

Copy link
Copy Markdown
Contributor

@benko-balog Should we just close this for now and re-open if ever needed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants