Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

AS 2 - From String to Number conversion Anomaly

New Here ,
Nov 24, 2007 Nov 24, 2007

There is some strange behavior into Flash subsystem about String --> Number conversion

Execute this simple code.


var strAux:String="1.15";
if(!isNaN(strAux)){
if(Number(strAux)>1.15){
trace("Error. This condition must be false")
}
//There is some sub system problem and I search it
if(Number(strAux)>=1.15000000000000001 && Number(strAux)<=1.15000000000000009){
trace("Range of problem")
}
//Illogical cases
if(Number(strAux)==1.15000000000000003){
trace("Correct digit found case 1")
}
if(Number(strAux)==1.15000000000000004){
trace("Correct digit found case 2")
}
if(Number(strAux)==1.15000000000000005){
trace("Correct digit found case 3")
}
}else{
trace("Please assign 1.15")
}
TOPICS
ActionScript
651
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 24, 2007 Nov 24, 2007
You haven't really explained what the problem is. My guess is that you are running into one well known problem of all computers and the other is a limit of Flash.

Sometimes and for certain values, the binary conversion from a decimal (in base 10) number with decimals (fractional numbers) to a binary (what the computer uses internally) and then back again will produce strange artifacts where a number will come out with a lot of zeros after the decimal and a 1. Or sometimes with a lot of nines. It is just the nature of trying to represent numbers in computer. All systems suffer from it, some use special techniques to overcome it - and some don't.

The other issue I think you are having is that Flash has 15 significant digits (I think that is it. So by having more than 15 places to the right all of those numbers are equal because flash isn't seeing that digit all the way out to the right.

If that isn't what your problem is, please let us know.

Finally, you aren't converting to a Number you are casting as a number. If you want to convert a string to a number use parseInt or parseFloat.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 24, 2007 Nov 24, 2007


Yes, the problem is it.
I know this problem in C++.
But AS2 is an authoring language and I think this problems can not appears into it.
I lost few minutes to found it but somebody can lost more hours?!

Regards
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 24, 2007 Nov 24, 2007


I used parseFloat() but problem is the same.
The conditiond are true.

if(parseFloat("1.15")>1.15){
trace(" 😮 ")
}

var strAux:String="1.15";
if(parseFloat(strAux)>1.15){
trace(" :~ ")
}

Have you a solution? I need precision.
Thanks
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 24, 2007 Nov 24, 2007
Sorry I don't I've never really had to deal with this. What exactly are you trying to do?
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 24, 2007 Nov 24, 2007
flash numbers are accurate to 15 decimal places. you're not going to get any more precision than that when using flash.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 24, 2007 Nov 24, 2007
hi, this is not a precision problem but of conversion accurance.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 24, 2007 Nov 24, 2007

Thanks for attention.
I am writing an funcion that compare a lot of decimal number.
the precision of these decimals is two.
I need that problems like:
if(parseFloat("1.15")>1.15){
trace(" 😮 ")
}

var strAux:String="1.15";
if(parseFloat(strAux)>1.15){
trace(" :~ ")
}

will not happens.
If I will found a solution I will happy to put it on line for contribute.


Regards
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 24, 2007 Nov 24, 2007
it's a precision problem. everything you've posted is related to a precision issue.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 24, 2007 Nov 24, 2007
Yes you are right, it is related to subsystem that reflects the problem to conversion mechanism.
Have you a solution?
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 24, 2007 Nov 24, 2007
:

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 24, 2007 Nov 24, 2007
ok, it appears to be a working solution.
Thank you
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 24, 2007 Nov 24, 2007
LATEST
you're welcome.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines