-
-
Notifications
You must be signed in to change notification settings - Fork 31.5k
Calculation error #12834
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
Comments
That is the expected behaviour per the ECMAScript spec, the binary numbers defined in IEEE 754-2008 behave that way. |
You can verify that in browser developers console (both Firefox and Chromium). Also you can verify that in other languages, e.g. With double x = 93.46 + 100.00 + 93.46;
std::cout << std::setprecision(20) << x << std::endl; will give you The only difference here is the default rounding of the output in C++ — to obtain similar results in JS, you would probably want to perform the rounding manually. |
echo ("php calculation\n93.46+100.00+93.46 = "); will show: |
@supachaiofficial That's rounding on the output (or, more specifically, on the default number-to-string conversion). php > echo number_format(93.46+100.00+93.46, 15)."\n";
286.919999999999959 You could verify that it's the rounding on the output/conversion with a similar example: php > echo 286.91999999999996 . "\n";
286.92 |
Version:
-> v4.8.1
-> v7.8.0
Platform:
-> Linux ip-172-31-17-62 4.4.0-72-generic [stream] support piping multiple streams into a single stream #93-Ubuntu SMP Fri Mar 31 14:07:41 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
-> Darwin supachai-macbook-pro.local 16.5.0 Darwin Kernel Version 16.5.0: Fri Mar 3 16:52:33 PST 2017; root:xnu-3789.51.2~3/RELEASE_X86_64 x86_64
Node Input:
console.log('print output: ',93.46+100.00+93.46)
Node Output:
print output: 286.91999999999996
Expect Correct Result:
print output: 286.92
The text was updated successfully, but these errors were encountered: