First posted a URL, feel written in very detailed, it seems that the principle of analysis, but did not see how, as if not to say how to solve ...
http://justjavac.iteye.com/blog/1864938
Phenomenon:
0.56 * - //56.00000000000001 0.56 * Ten //5.6000000000000005 0.57 * Ten //5.699999999999999 5.6 / Ten //0.5599999999999999
This is true for all browsers including IE6
Scene appears
Need to show 0.56 as 56%, then incredibly 56%, no words.
Solve:
Seems normal:
0.57*1000/10
But the problem remains:
0.5757 * + / Ten //57.57000000000001
The reasons are:
575.7 / Ten //reason is 5.7 except ten
Rule of discovery: avoid 0.56 or two decimal places near 5.6 to 100 or 10 multiplication
so: Multiply the number one bit more than the decimal, and then remove the extra multiples.
0.5757 * 100000 / + //Normal
But this kind of scheme, does not rely on the principle, relies on most intuition, therefore, on the hard recruit:
Turn the string first, and then move the decimal point. But this kind of scheme is less efficient ...
function topercent(Num) { varArr= (Num+ "').Split('. '),Otherhalf= (Arr[1] ?Arr[1] : "') + ' a ';Otherhalf=Otherhalf.substr(0, 2) + '. ' +Otherhalf.substr(2); return (Arr[0] +Otherhalf) * 1;}topercent(. $) ///topercent(5.7) //570topercent( $) //5700
Floating point number! By 100, 10 after the accuracy change!