Skip to content
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

add-Num#bigDecimalValue #1109

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

nimo23
Copy link
Contributor

@nimo23 nimo23 commented Sep 4, 2023

Fixes #.

Changes proposed in this pull request:

  • added Num.bigDecimalValue() to convert the Num to a BigDecimal

    • For DecimalNum it returns its delegate
    • For DoubleNum it converts by BigDecimal.valueOf(delegate) (if delegate is NaN or Infinity, then it simply returns null)
    • For NaN it simply returns null.
  • added an entry with related ticket number(s) to the unreleased section of CHANGES.md

Actually, it's not easy to get the BigDecimal-representation of a Num. We have intValue(), longValue(), doubleValue(), etc. so it also makes sense to add bigDecimalValue().

@nimo23
Copy link
Contributor Author

nimo23 commented Sep 4, 2023

Would it be better to overwrite bigDecimalValue() in its subclasses instead of providing a default method?

For example, in DecimalNum:

 @Override
 public BigDecimal bigDecimalValue() {
        return delegate;
}

With this, no if and cast is needed..

@TheCookieLab
Copy link
Member

Would it be better to overwrite bigDecimalValue() in its subclasses instead of providing a default method?

For example, in DecimalNum:

 @Override
 public BigDecimal bigDecimalValue() {
        return delegate;
}

With this, no if and cast is needed..

Yes, that would be ideal.

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.

None yet

2 participants