format - How to fix 2 decimal points in ActionScript 2 -


how can fix number value 2 decimal points in actionscript 2?

actionscript 3's tofixed() doesn't work me.

e.g:

1 => 1.00 

it turns out can achieved function:

//format number specified number of decimals function formatdecimals(num, digits) {     //if no decimal places needed, we're done     if (digits <= 0) {         return math.round(num);     }     //round number specified decimals     var tentopower = math.pow(10, digits);     var cropped = string(math.round(num * tentopower) / tentopower);     //add decimal point if missing     if (cropped.indexof(".") == -1) {         cropped += ".0";     }     //finally, force correct number of zeroes; add if necessary     var halves = cropped.split("."); //grab numbers right of decimal     //compare digits in right half of string digits wanted     var zerosneeded = digits - halves[1].length; //number of zeros add     (var i=1; <= zerosneeded; i++) {         cropped += "0";     }     return(cropped); } 

Comments

Popular posts from this blog

assembly - 8086 TASM: Illegal Indexing Mode -

Java, LWJGL, OpenGL 1.1, decoding BufferedImage to Bytebuffer and binding to OpenGL across classes -

javascript - addthis share facebook and google+ url -