469,366 Members | 2,218 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,366 developers. It's quick & easy.

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

Hello,
in vbscript:
Int(11.4)=11

What function in JScript like this function?
Thank you

Jul 19 '05 #1
5 8708
"W. Jack" wrote in message news:uD*************@tk2msftngp13.phx.gbl...
: 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
Jul 19 '05 #2
Roland Hall wrote on 13 mei 2004 in
microsoft.public.inetserver.asp.general:
"W. Jack" wrote in message news:uD*************@tk2msftngp13.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)

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>

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jul 19 '05 #3
Thank you very much

Jul 19 '05 #4
Thank you very much

Jul 19 '05 #5
"Evertjan." wrote in message news:Xn********************@194.109.133.29...
: Roland Hall wrote on 13 mei 2004 in
: microsoft.public.inetserver.asp.general:
:
: > "W. Jack" wrote in message news:uD*************@tk2msftngp13.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);

Results: 11, -12

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

Results: 11, -12
Jul 19 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

20 posts views Thread by Harag | last post: by
4 posts views Thread by Harag | last post: by
15 posts views Thread by Laser Lu | last post: by
3 posts views Thread by Christopher Brandsdal | last post: by
10 posts views Thread by Christopher Brandsdal | last post: by
26 posts views Thread by Roland Hall | last post: by
26 posts views Thread by Lasse Edsvik | last post: by
5 posts views Thread by Maxwell2006 | last post: by
7 posts views Thread by FAQ server | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.