...

View Full Version : parseFloat problem



Psirus
05-29-2008, 05:47 PM
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?

gnomeontherun
05-29-2008, 06:03 PM
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.


var max:Number = ....

Psirus
05-29-2008, 06:33 PM
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.

gnomeontherun
05-30-2008, 06:39 AM
This doesn't help?

function onMaxData(n:Number) {
var max:Number = Number(n);
trace(parseFloat(max)); // 0
trace (max);
msg = "Received data from server: " + max;
trace(typeof (max));

}



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum