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

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • W. Jack

    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

  • Roland Hall

    #2
    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?

    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


    Comment

    • Evertjan.

      #3
      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

      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.floo r( 11.4) ) // 11
      //alert(Math.floo r( 011.4) ) // error
      alert(Math.floo r( '011.4') ) // 11
      alert(Math.floo r( '-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)

      Comment

      • W. Jack

        #4
        Re: What function in JScript like VBScript's Int() function

        Thank you very much

        Comment

        • W. Jack

          #5
          Re: What function in JScript like VBScript's Int() function

          Thank you very much

          Comment

          • Roland Hall

            #6
            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);

            Results: 11, -12

            WScript.Echo(In t(11.4))
            WScript.Echo(In t(-11.4))

            Results: 11, -12


            Comment

            Working...