下面將確保任何大量只精確到百位(related to this answer):如何讓數字具有.05的精度?
public function round(sc:Number):Number
{
sc = sc * 100;
sc = Math.floor(sc);
sc = sc/100;
return sc;
}
什麼是圓我號碼.05精度的最佳方法是什麼?爲了獲得這個結果,是否有一些聰明的工作要做?例如,我想:
3.4566 = 3.45
3.04232 = 3.05
3.09 = 3.1
3.32 = 3.3
這應該是Math.round(),而不是Math.floor()。 – Svante 2009-04-28 21:02:01