Re: What function in JScript like VBScript's Int() function
"W. Jack" wrote in message news:uDu8ZhKOEH A.556@tk2msftng p13.phx.gbl...
: Hello,
: in VBScript:
: Int(11.4)=11
:
: What function in JScript like this function?
Re: What function in JScript like VBScript's Int() function
Roland Hall wrote on 13 mei 2004 in
microsoft.publi c.inetserver.as p.general:
[color=blue]
> "W. Jack" wrote in message news:uDu8ZhKOEH A.556@tk2msftng p13.phx.gbl...
>: Hello,
>: in VBScript:
>: Int(11.4)=11
>:
>: What function in JScript like this function?
>
> parseInt(11.4)
>[/color]
should be:
parseInt( '11.4', 10)
But I prefer Math.floor()
parseInt() acts nearly like Fix()
Math.floor() more like Int()
=============== ============
tested on IE6:
<script>
// javascript test, no type spec, sorry puritans
Re: What function in JScript like VBScript's Int() function
"Evertjan." wrote in message news:Xns94E85D4 B4CA95eejj99@19 4.109.133.29...
: Roland Hall wrote on 13 mei 2004 in
: microsoft.publi c.inetserver.as p.general:
:
: > "W. Jack" wrote in message news:uDu8ZhKOEH A.556@tk2msftng p13.phx.gbl...
: >: Hello,
: >: in VBScript:
: >: Int(11.4)=11
: >:
: >: What function in JScript like this function?
: >
: > parseInt(11.4)
: >
:
: should be:
:
: parseInt( '11.4', 10)
It said the radix was optional but prefix 0x would be seen as hex and prefix
0 octal, all others decimal.
It [docs] also said it wants a string but didn't complain when I passed a
float. Go figure.
: But I prefer Math.floor()
:
: parseInt() acts nearly like Fix()
: Math.floor() more like Int()
Ya', the signed numbers make the difference.
function parseit(x) {
var a = parseInt(x);
WScript.Echo(a) ;
}
parseit(11.4);
parseit(-11.4);
Results: 11, -11
function floorit(x) {
var a = Math.floor(x);
WScript.Echo(a) ;
}
floorit(11.4);
floorit(-11.4);
Comment