Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Mar 2008
    Posts
    27
    Thanks
    10
    Thanked 0 Times in 0 Posts

    parseFloat problem

    I am receiving a variable which is numbers, but recognized as a string.
    It is a constantly changing number, currently random between 0 and 40.

    The variable is called 'max'

    I am trying to convert this variable to a number

    When I use:
    trace(parseFloat(max));
    This works as the output screen, the numbers are outputting without a semi colon.

    When I try to do this:
    parseFloat(max);
    trace (max);
    trace(typeof (max));
    It outputs the number with a semicolon, and outputs the type as String.


    I have referred to the Flash help file and it states:
    parseFloat(string:String) : Number
    When I try
    parseFloat(max:String) : Number
    It errors on me.

    Any ideas?

  • #2
    Senior Coder gnomeontherun's Avatar
    Join Date
    Sep 2007
    Location
    Houston
    Posts
    2,846
    Thanks
    10
    Thanked 238 Times in 229 Posts
    When you initially create the variable max type it as a number like this. You want to have it start as a number instead of as a string and then convert it, it just gets more confusing.

    Code:
    var max:Number = ....

  • #3
    New Coder
    Join Date
    Mar 2008
    Posts
    27
    Thanks
    10
    Thanked 0 Times in 0 Posts
    function onMaxData(n:Number) {
    var max = n;
    trace(parseFloat(max)); // 0
    trace (max);
    msg = "Received data from server: " + max;
    trace(typeof (max));

    }
    'max' is coming from a 3rd party program. There is no point going into detail about it, but just think it is a random number between 0 and 40.

  • #4
    Senior Coder gnomeontherun's Avatar
    Join Date
    Sep 2007
    Location
    Houston
    Posts
    2,846
    Thanks
    10
    Thanked 238 Times in 229 Posts
    This doesn't help?
    Code:
    function onMaxData(n:Number) {
    var max:Number = Number(n);
    trace(parseFloat(max)); // 0
    trace (max);
    msg = "Received data from server: " + max;
    trace(typeof (max));
    
    }


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •