$yuejie = 0;
$yuejie + = $v [' Yuejie '];
$v [' Yuejie '] data into
Accumulate results into
The third row of data should be 0, but it shows 3.5527136788005E-15, which is why?
Reply to discussion (solution)
Are you asleep?
No data code, guess ...
Look at Echo Php_int_max; Output what?
3.5527136788005E-15 is a very small number (not even the scientific notation), and we can think of him as 0.
As for how is not the real 0, then ask you to review the computer in the basic knowledge of the representation of the number
Also please review the knowledge of the effective number
3.5527136788005E-15 is a very small number (not even the scientific notation), and we can think of him as 0.
As for how is not the real 0, then ask you to review the computer in the basic knowledge of the representation of the number
Also please review the knowledge of the effective number
But I do not understand, the cumulative result should be 0, why will it become like this? And my data are two decimal places, how can it be this way?
3.5527136788005E-15 is a very small number (not even the scientific notation), and we can think of him as 0.
As for how is not the real 0, then ask you to review the computer in the basic knowledge of the representation of the number
Also please review the knowledge of the effective number
Pro, help me to say how to solve, I now do project encounter this problem, if again go to book study, it is too late.
The ToFixed method returns a string representing a number represented by a fixed-point notation. Numobj.tofixed ([fractiondigits]) parameter numobj required option. A number object. FractionDigits options available. Number of digits after the decimal point. Its value must be at 0? Between 20, including 0 and 20. Description The Tofixed method returns a string representation of a number in fixed-point notation. There is a valid number before the decimal points of the string, and must then contain fractiondigits digits. If there is no fractiondigits parameter, or the parameter is the Undefined,tofixed method, the value is assumed to be 0.
Keep 2 decimal places for the data you are displaying
A = -80.27;b = 53.51;c = 26.76;document.write ((a+b+c). toFixed (2));
0.00
Yo, it's wrong! I thought it was a JS problem.
The calculation accuracy problem is calculated without undue consideration, otherwise the error accumulates faster
Just handle the right precision when you display it.
$yuejie = 0; $a = array (' yuejie ' = + -80.27), array (' yuejie ' = = 53.51), array (' Yuejie ' = 26.76), array (' Yuejie ' = -38.29), array (' yuejie ' = = 38.29),), foreach ($a as $v) { $yuejie + = $v [' Yuejie ']; printf ("%8.2f%8.2f\n", $v [' Yuejie '], $yuejie);}
-80.27 -80.27 53.51 -26.76 26.76 0.00 -38.29 -38.29 38.29 0.00
The problem is solved, the result of each accumulation is rounded, the decimal point becomes 0.