如何获得数字精度为.05?

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

Chr*_*ill 6

您可以乘以20,然后除以20.

编辑:您将需要使用Math.round()而不是Math.floor(),否则您的测试用例3.09将变为3.05.