jed*_*ikb 3 math floating-point actionscript rounding actionscript-3
以下内容将确保任何大数字仅精确到百分位(与此答案相关):
public function round( sc:Number ):Number
{
sc = sc * 100;
sc = Math.floor( sc );
sc = sc / 100;
return sc;
}
Run Code Online (Sandbox Code Playgroud)
将数字四舍五入到.05精度的最佳方法是什么?是否有一些聪明的事情需要通过位移来获得这个结果?例如,我想:
3.4566 = 3.45
3.04232 = 3.05
3.09 = 3.1
3.32 = 3.3