Recently, standardized web development has caught a cold, so fixfox is always used as a browser. However, since the system we are working on does not support non-ie browsers at all, we have to use IE during development, write some small tests Program I used Firefox, and the functions I made yesterday were rounded down. So I thought of the tofixed () function. I wrote a simple test program and tested it under fixfox. < Script Language = " Javascript " >
Function Test ()
{
Alert ( 20.365 . Tofixed ( 2 ));
Alert ( 20.364 . Tofixed ( 2 ));
Alert ( 20.366 . Tofixed ( 2 ));
Alert ( 20.355 . Tofixed ( 2 ));
Alert ( 20.354 . Tofixed ( 2 ));
Alert ( 20.356 . Tofixed ( 2 ));
}
</ Script >
< Body onload = " Test (); " >
In fixfox, 20.36, 20.36, 20.37, 20.36, 20.35, 20.36
Obviously, this is the same as the round method in C #. It adopts the banker's rounding method, "four homes, six homes, five get even ".
I have long heard of the differences between the parsing of Javascript in IE and Firefox. So I started to test it in IE before, and the results are really different.
In IE, 20.37, 20.36, 20.37, 20.36, 20.35, 20.36, are displayed in sequence.
Obviously, ie is rounded down.Algorithm.
Microsoft is really weird. Why don't we leave it alone.