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

When using BrowserCompatible, BigDecimal in the Double range behaves the same as Double. for issue #3123 #3136

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

rowstop
Copy link
Contributor

@rowstop rowstop commented Oct 26, 2024

What this PR does / why we need it?

Summary of your change

public static boolean isJavaScriptSupport(BigDecimal decimal) {
        boolean jsSupport = decimal.precision() < 16 || isJavaScriptSupport(decimal.unscaledValue());
        if (!jsSupport && decimal.scale() != 0) {
            //Use double for comparison
            //double and javascript number have the same precision
            //In extreme cases, precision loss may occur.
            //There will be a loss of precision between [4.9e-324, 5e-324), which will be converted to 5e-324 by JavaScript.
            //This situation can be ignored
            double doubleValue;
            try {
                doubleValue = decimal.doubleValue();
            } catch (Exception ex) {
                return false;
            }
            jsSupport = decimal.compareTo(BigDecimal.valueOf(doubleValue)) == 0;
        }
        return jsSupport;
    }

Please indicate you've done the following:

  • Made sure tests are passing and test coverage is added if needed.
  • Made sure commit message follow the rule of Conventional Commits specification.
  • Considered the docs impact and opened a new docs issue or PR with docs changes if needed.

@wenshao
Copy link
Member

wenshao commented Oct 26, 2024

这个没解决Double输出的问题吧

@rowstop
Copy link
Contributor Author

rowstop commented Oct 28, 2024

这个没解决Double输出的问题吧

double 和 javascript 的 Number 范围相似,只有在±Double.MIN_VALUE时会被转为±5e-324,这种情况可以忽略了,可以认为 Double 不需要额外处理

@rowstop
Copy link
Contributor Author

rowstop commented Oct 28, 2024

image

image

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.

2 participants