1 Reply Latest reply on Sep 8, 2007 12:28 AM by Ansury

    Fault conversion, from Number to String and vice versa.

    snoby
      Hello,

      When I execute the following code in Flex, it changes the value in a conversion from a String to a Number and vice versa.

      code:
      [code]
      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="setup();">
      <mx:Script>
      <![CDATA[
      import mx.controls.Alert;
      private var cadena:String="99999999999999999";
      private function setup():void{
      Alert.show("String: "+cadena+"\nNumber: "+ Number(cadena).toString());
      trace("String: "+cadena+"\nNumber: "+ Number(cadena).toString());
      }
      ]]>
      </mx:Script>
      </mx:Application>
      [/code]

      Output:
      [quote]
      String: 99999999999999999
      Number: 100000000000000000 [/quote]

      It happens as much in Flex 2.0.1 as in Flex 3.
      Somebody can help me to resolve this.

      Manu.
        • 1. Re: Fault conversion, from Number to String and vice versa.
          Ansury Level 3
          Looks like you're going over the limit of the Number data type. From the Docs: "The Number data type can use up to 53 bits to represent integer values, compared to the 32 bits available to int and uint."

          That number with all the 9s needs 57 bits, so it's too big. Delete two of the 9s and it works fine, because it fits into the data type's maximum range.