cocos / cocos-engine

Cocos simplifies game creation and distribution with Cocos Creator, a free, open-source, cross-platform game engine. Empowering millions of developers to create high-performance, engaging 2D/3D games and instant web entertainment.
https://www.cocos.com/en/creator
Other
8.66k stars 2.02k forks source link

Long float dots had a bad format #17807

Open longchuan opened 2 weeks ago

longchuan commented 2 weeks ago

Cocos Creator version

3.8.4

System information

windows 11

Issue description

image Long float dots had a bad format expect to have a float format ,not a scientific notation format.

Relevant error log output

No response

Steps to reproduce

This method will solve the problem

public static getFloatString (strNum: number): string {
        let str = String(strNum);
        if (str.indexOf("e") !== -1) {
            let strArr = str.split("e");

            let factor = strArr[0].split(".");

            let powNum = parseInt(strArr[1]);
            if (powNum < 0) {
                return "0" + "." + "0".repeat(-powNum - factor[0].length) + factor[0] + (factor.length === 2 ? factor[1] : "");
            } else {
                if (factor.length === 2) {
                    let dotNum = powNum - factor[1].length;
                    if (dotNum < 0) {
                        let spl = factor[1].slice(0, -dotNum);
                        return factor[0] + spl[0] + "." + spl[1];
                    } else {
                        return factor[0] + factor[1] + "0".repeat(dotNum - factor[0].length);
                    }
                } else {
                    return factor[0] + "0".repeat(powNum - factor[0].length);
                }
            }
        } else {
            return str;
        }
    }

Minimal reproduction project

No response

wuzhiming commented 2 weeks ago

@yufengctbu check the design doc or issue to see the purpose of why we're doing this.