why math wont work?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Lasse Reichstein Nielsen

    #16
    Re: why math wont work?

    "Dauber!" <dau_ber@verizo n.SPAMISFOREATI NG.net.invalid> writes:
    [color=blue]
    > Uhhh....yes. Believe it or not, despite popular belief, not all browsers
    > interpret JavaScript the same way, including two of the ones I use.[/color]

    Could you be persuaded to tell us what browsers those are?

    If prefix plus isn't working consistently accross browsers, we should
    ofcourse make a note of it.
    The expected behavior (from the ECMAScript standard) is to be equivalent
    to calling the Number function, but without the overhead of a function call.
    [color=blue]
    > Funny...two references I checked, including one that helped me get an A in
    > my JavaScript programming class that I took for my webmaster admin
    > certification, indicates that it's perfectly valid;[/color]

    It is valid.
    [color=blue]
    > in fact, I'm given several overloaded versions tht account for "0x"
    > format as well as binary and octal...[/color]

    Overloaded?

    Anyway, it is the collective experience in this group, that people
    using parseInt most likely expect it to convert from base 10. That is
    why we recommend also passing the radix to the function, to avoid
    surprises when a user entered number starts with zero.

    If you know what you are doing, using parseInt without the radix is
    correct. It's just not good advice to a beginner without telling why
    "089" converts to 0 in some browsers and 89 in others.

    Not all browsers accept octal numbers as arguments to parseInt (as,
    indeed, they shouldn't according to ECMA 262). But IE does. So any way
    you put it, omitting the radix will make your page behave inconsistently
    across browsers.

    /L
    --
    Lasse Reichstein Nielsen - lrn@hotpop.com
    DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
    'Faith without judgement merely degrades the spirit divine.'

    Comment

    • HikksNotAtHome

      #17
      Re: why math wont work?

      In article <992.478T2337T1 4296243dau_ber@ verizon.SPAMISF OREATING.net.in valid>,
      "Dauber!" <dau_ber@verizo n.SPAMISFOREATI NG.net.invalid> writes:
      [color=blue][color=green][color=darkred]
      >>>> var x = (+y) + 3 * 7;
      >>>
      >>>That'll still give the same result, unfortunately. Whatcha need to do is
      >>>this;[/color][/color]
      >[color=green]
      >>Did you bother testing that before spouting off that it would give the same
      >>results?[/color]
      >
      >Uhhh....yes. Believe it or not, despite popular belief, not all browsers
      >interpret JavaScript the same way, including two of the ones I use.[/color]

      So you have a browser that doesn't convert a string to a number using + ?
      Ex:

      x = "3";
      y = +x;
      alert(typeof(y) ); //browser that alerts string instead of number??

      I am not in a position to doubt you about it, would be curious to know of it
      though. I know of at least 130 browsers so one might not convert it to number.
      If it doesn't, then it would definitely be worth knowing about.
      [color=blue][color=green]
      >>It is *well* known in this group that +y where y is a number in a string
      >>format is quicker at converting it to a number than parseInt is, which you
      >>use incorrectly.[/color]
      >
      >Funny...two references I checked, including one that helped me get an A in
      >my JavaScript programming class that I took for my webmaster admin
      >certificatio n, indicates that it's perfectly valid; in fact, I'm given
      >several overloaded versions tht account for "0x" format as well as binary
      >and octal...[/color]

      valid in the sense of a limited subset of numbers, it works, then yes its
      valid.

      alert(parseInt( '08'))
      And you get 0, not 8.
      The incorrectness of your use was the lack of a radix (base 10).

      <URL:

      html/jsmthparseint.a sp />
      --
      Randy

      Comment

      • Dauber!

        #18
        Re: why math wont work?

        Waaaaay back on 15-Dec-03 07:31:06, HikksNotAtHome said this about Re: why math wont work?:
        [color=blue][color=green]
        >>Uhhh....yes . Believe it or not, despite popular belief, not all browsers
        >>interpret JavaScript the same way, including two of the ones I use.[/color][/color]
        [color=blue]
        >So you have a browser that doesn't convert a string to a number using + ?
        >Ex:[/color]
        [color=blue]
        >x = "3";
        >y = +x;
        >alert(typeof(y )); //browser that alerts string instead of number??[/color]

        The latest Voyager for Amiga. Yeah, I know, the vast majority of users don't
        use Amiga, but I'm a very stubborn advocate for universality. :) Not the
        greatest browser in the world, either...fast, but not great.
        [color=blue][color=green]
        >>Funny...two references I checked, including one that helped me get an A in
        >>my JavaScript programming class that I took for my webmaster admin
        >>certification , indicates that it's perfectly valid; in fact, I'm given
        >>several overloaded versions tht account for "0x" format as well as binary
        >>and octal...[/color][/color]
        [color=blue]
        >valid in the sense of a limited subset of numbers, it works, then yes its
        >valid.[/color]

        DUH!....forgot the "10" parameter. <blush>

        --
        dauber@banana-and-louie.oops.org
        * ICQ: 28677921 * YIM: dau_ber * AIM: ddaauubbeerr

        Comment

        • Richard Cornford

          #19
          Re: why math wont work?

          "Dauber!" <dau_ber@verizo n.SPAMISFOREATI NG.net.invalid> wrote in message
          news:1147.479T1 499T6255001dau_ ber@verizon.SPA MISFOREATING.ne t.invalid...
          <snip>[color=blue][color=green]
          >>So you have a browser that doesn't convert a string to
          >>a number using + ?
          >>Ex:[/color]
          >[color=green]
          >>x = "3";
          >>y = +x;
          >>alert(typeof( y)); //browser that alerts string instead of number??[/color]
          >
          >The latest Voyager for Amiga.[/color]

          Does it claim its script language implementation is ECMA 262 compliant?
          If not why not (the current version has been around since 1999) and if
          they do, have they been told they have a bug to fix?

          How do the other type-converting math operators perform? Does y = -x;
          also return a string?
          [color=blue]
          >Yeah, I know, the vast majority of users don't
          >use Amiga, but I'm a very stubborn advocate for
          >universality . :) ...[/color]
          <snip>

          You will find that the majority here are also advocates of universality,
          but if a browser manufactures decides to implement there own scripting
          language without regard for either the published standard or precedence
          and then tries to execute it when provided with JavaScript/ECMA Script
          source code there is only so much that can be done.

          Richard.


          Comment

          • Thomas 'PointedEars' Lahn

            #20
            Re: why math wont work?

            Lasse Reichstein Nielsen wrote:
            [color=blue]
            > Thomas 'PointedEars' Lahn <PointedEars@we b.de> writes:[color=green]
            >> My Opera/7.11 (Windows NT 5.0; U) [en] returns `null', too.[/color]
            >
            > My Opera/7.23 (Windows NT 5.1; U) [en] returns 'undefined'
            >[color=green]
            >> javascript:aler t(typeof prompt("bla")) // `object' if canceled[/color]
            >
            > on this exact test.[/color]

            Straynge. [psf 4.15]


            PointedEars :)

            Comment

            Working...