Reputation: 442
I am facing the problem on multiplying two decimal number in flex.
When i am multiplying two decimal number the result is like a exponential number so i don't know how to get the decimal number as a result instead of getting an exponential number.
I am using the following codes to make a multiplication:
var num1:Number = 0.00005;
var num2:Number = 0.000007;
var result:Number = num1 * num2;
And in result variable i am getting the value as 3.5000000000000003E-10
.
So i don't know how to get decimal number as result instead of getting an exponential number as above.
If anybody have knowledge how to resolve this problem please help me to solve.
Upvotes: 3
Views: 363
Reputation: 3234
You need to use the .toPrecision(precision:uint)
method available in the Number
class. This method takes one parameter which is :
precision:uint — An integer between 1 and 21, inclusive, that represents the desired number of digits to represent in the resulting string.
So simply do :
trace(result.toPrecision(2));
And you should get an output of 0.00000000035
Official documentation here :
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/Number.html#toPrecision()
Hope this helps. Cheers.
Upvotes: 6