|
Blue Forest http://www.lslnet.com at 6:28 p.m. on August 22, 2006
JavaScript integer computation how China?
Not Int?
|
Math.round () |
Thanks! |
Math.round () is the way the entire numerical approximation rather than take the whole
Should [color=red]parseInt[/color]
1, the conversion to take the entire string
[html]<script>
Alert (parseInt ( "11.9"))
"/script>
[/html]
2, to take full float
[html]<script>
Alert (parseInt (11.9))
"/script>
[/html] |
ParseInt string into cosmetic surgery for the general, if not rounded integer, we should use
Math.floor |
Myhyli said in a message
Please withheld earlier comparison
[html]
"Script>
Alert (parseInt (-11.9))
"/script>
[/html]
[html]
"Script>
Alert (Math.floor (-11.9))
"/script>
[/html]
I think integer say, is to use [color=red]parseInt[/color], there is no other
: P |
Math.floor () the small 4.8->4 4.2->4
Math.ceil () large 4.8->5 4.2->5
Math.round () rounded 4.8->5 4.2->4
ParseInt (char) char to int number switch |
[html]
"Script>
N = -11.9
A = new Date (). GetTime ()
For (var i=0; i<100000; i++) parseInt (-.5)
//for (Var i=0; i<100000; i++) nn%1
//for (Var i=0; i<100000; i++) -11.9|0
Alert ((new Date (). GetTime ()) -)
"/script>
[/html] |
As expected by bit operation is the fastest : D
|
TU good bt die. . . Eastern well. . . Thinking. . |
-11.9|0
Understand why caput "or" take on the whole operation? ? ? |
|