Casting to a Number: Number(stringValue) : Number « Data Type « Flash / Flex / ActionScript






Casting to a Number: Number(stringValue)

 

package{
  import flash.display.Sprite;
  
  public class Main extends Sprite{
    public function Main(){
        var nOne:Number = Number("468");    // 468
        var nTwo:Number = Number("23.45");  // 23.45
        var nThree:Number = Number("abc");    // NaN (Not a Number)
        var nFour:Number = Number("0101");   // 65 (Octal)
    }
  }
}

        








Related examples in the same category

1.Use Number type variable in for loop
2.Read and write to a variable
3.Decimal Numbers
4.Dealing with Infinite Values: Number.POSITIVE_INFINITY and Number.NEGATIVE_INFINITY
5.Handling Minimum and Maximum Values: MAX_VALUE and MIN_VALUE
6.Minimum and Maximum Values for uint and int
7.Working with Number Instances
8.The default value for an unassigned variable of type Number is NaN
9.Not a Number: use the top-level function isNaN()