1 Reply Latest reply on Oct 4, 2007 6:54 AM by ale500

    text to number and decimalSeparator

      Hi, I need to convert a text (in a textImput) to Number.

      Some times the user type: 1000.10 or 1000,10 do represent the same number (one thousand and 10 cents)

      the problema is that 1000,10 gives me NaN using the simple way: Number(mytxt.text)

      How can I solve this problem?
        • 1. Re: text to number and decimalSeparator
          If there is no thousands separator (Like: english 1,000.00 represents one thousand; spanish/german: 1.000,00 represents the same thousand):

          I'd replace the comma with a decimal point (using indexOf to find it), and later use Number() to convert:

          s = textInput.text;
          if (s.indexOf(",") != -1)
          s = s.substr(0, s.indexOf(",") + "." + s.substr(s.indexOf(",")+1, s.length - 1 - s.indexOf(",");

          number = Number(s);

          I hope is readable :-), and helps