[Yahoo!知識+] Flash怎麼把數值求到小數點後兩位
Published on 12/03,2006
http://tw.knowledge.yahoo.com/question/?qid=1206102912349
Q:Flash怎麼把數值求到小數點後兩位
利用actionscript寫
要怎麼把求出來的數值
表示到小數點後兩位呢^^?
先寫一小段處理數字的小程式:
function trans(num, precision, splitCharacter) {
if ((precision=Math.abs(precision)) == 0) {
return Math.round(num);
}
if (splitCharacter == null) {
splitCharacter = ".";
}
return Math.round(num)+splitCharacter+Math.round(num*Math.pow(10, precision)).toString().substr(-precision);
}
例如原本的數字是A = 333.33333
trace(trans(A, 2));
它就只會印出333.33了
希望有幫上忙 :)