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

关于先乘后除的问题 #378

Open
zimo1213 opened this issue Mar 10, 2025 · 0 comments
Open

关于先乘后除的问题 #378

zimo1213 opened this issue Mar 10, 2025 · 0 comments

Comments

@zimo1213
Copy link

    @Test
    public void test() throws Exception {
        ExpressRunner runner = new ExpressRunner(true, true);
        DefaultContext<String, Object> context = new DefaultContext<>();
        context.put("a", 5006d);
        context.put("b", 7d);
        context.put("c", 28d);
        Object r = runner.execute("a * b / c", context, null, true, true);
        Object r2 = runner.execute("a / c * b", context, null, true, true);

        System.out.println(r);
        System.out.println(r2);
        System.out.println(5006d * 7d / 28d);
        System.out.println(5006d / 28d * 7d);
    }

得到结果
1251.5000000000
1251.49999999990
1251.5
1251.5

为什么先乘后除 和 先除后乘 结果不一致呢

3.3.4

@zimo1213 zimo1213 reopened this Mar 10, 2025
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

No branches or pull requests

1 participant