How do I convert exponential number to decimal numbers in action script 3?

I am facing the problem of multiplying two decimal numbers in flex.

When I multiply two decimal numbers, the result is like an exponential number, so I don't know how to get the decimal number from the result instead of getting the exponential number.

I am using the following codes to create multiplication:

var num1:Number = 0.00005;
var num2:Number = 0.000007;
var result:Number = num1 * num2;

      

And in the result variable, I get the value as 3.5000000000000003E-10

.

So, I don't know how to get the decimal number as the result instead of getting the exponential number as above.

If anyone has any knowledge on how to solve this problem, please help me solve.

+3


source to share


1 answer


You need to use a method .toPrecision(precision:uint)

available in the class Number

. This method takes one parameter, which:

precision: uint . An integer between 1 and 21, inclusive, that represents the desired number of digits to represent in the resulting string.

So simple:

trace(result.toPrecision(2));

      



And you should get an output 0.00000000035

Official documentation here:

http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/Number.html#toPrecision ()

Hope this helps. Greetings.

+6


source







All Articles