LayaBox Bug -- number类型精度问题

当然这个标题是有问题的,与其说是LayaBox的number精度问题还不如说是TypeScript的精度问题,或者说是JavaScript的精度问题。先看一个测试用例和输出看看这个问题有多严重。

class Degree{
    constructor(){
        Laya.init(600, 400);
        let result = 0;
        for (var i = 0; i < 100; i++) {
            result = result + i + 1.9;
            console.log("result:" + result);
        }
    }
}

new Degree();

输出LayaBox Bug -- number类型精度问题_第1张图片
在LayaBox的Math类中提供了很多很好用的函数,比如Math.floor,Math.ceil,Math.round等方法,我们要知道我们要的数据的情况然后在使用提供的函数,来避免精度给我们带来数据上的错误。

你可能感兴趣的:(LayaBox,LayaBox)