-
Display percentage?
I bet the answer lies within the preloaders and I could study them to reach it, but to cut a corner.
If I want to display the percentage, by calculating it, e.g.:
65 / 250 gives the result 0.264 and means that 65 is 26.4 percent of 250
But how do I make my flashmovie display only 26 ? Or even in som cases there would be more decimals and I could be satisfied with the display of 2 like this 0.26 - buit not more, how is that possible?
-
-
That would turn 26.4 into 26 surely, but how to turn 0.264 into 26?
EDIT* wait a minute ( times 100 and Math.round(number) )would do it! Solved!
-
Code:
//n = number;
//m = numbers after the decimal point;
Math.roundN = function (n,m) {
return Math.round((n*Math.pow(10,m)))/Math.pow(10,m)
}
//example
my_num = Math.roundN((1.12345), 2);