What function in JScript like VBScript's Int() function

W

W. Jack

Hello,
in VBScript:
Int(11.4)=11

What function in JScript like this function?
Thank you
 
R

Roland Hall

in message : Hello,
: in VBScript:
: Int(11.4)=11
:
: What function in JScript like this function?

parseInt(11.4)

--
Roland Hall
/* This information is distributed in the hope that it will be useful, but
without any warranty; without even the implied warranty of merchantability
or fitness for a particular purpose. */
Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
WSH 5.6 Documentation - http://msdn.microsoft.com/downloads/list/webdev.asp
MSDN Library - http://msdn.microsoft.com/library/default.asp
 
E

Evertjan.

Roland Hall wrote on 13 mei 2004 in
microsoft.public.inetserver.asp.general:
in message : Hello,
: in VBScript:
: Int(11.4)=11
:
: What function in JScript like this function?

parseInt(11.4)

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

alert(parseInt( 11.4 ) ) // 11
alert(parseInt( -11.4 ) ) // -11
//alert(parseInt( 011.4 ) ) // error !!!!!
alert(parseInt( '011.4' ) ) // 9 octal !!!!
alert(parseInt( '-011.4', 10) ) // -11

alert(Math.floor( 11.4) ) // 11
//alert(Math.floor( 011.4) ) // error
alert(Math.floor( '011.4') ) // 11
alert(Math.floor( '-011.4') ) // -12

</script>

<script language=vbs>
// vbscript test, outdated type spec, sorry puritans
// alert is accepted as is the // instead of '

alert(Int( 11.4 ) ) ' 11
alert(Int( -11.4 ) ) ' -12
alert(Int( -011.4 ) ) ' -12

alert(Fix( 11.4 ) ) ' 11
alert(Fix( -11.4 ) ) ' -11

</script>
 
R

Roland Hall

in message : Roland Hall wrote on 13 mei 2004 in
: microsoft.public.inetserver.asp.general:
:
: > "W. Jack" wrote in message : >: 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);

Results: 11, -12

WScript.Echo(Int(11.4))
WScript.Echo(Int(-11.4))

Results: 11, -12
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,767
Messages
2,569,570
Members
45,045
Latest member
DRCM

Latest Threads

Top