Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Long float dots had a bad format #17807

Open
longchuan opened this issue Nov 4, 2024 · 1 comment
Open

Long float dots had a bad format #17807

longchuan opened this issue Nov 4, 2024 · 1 comment
Assignees
Labels
Bug Needs Triage Needs to be assigned by the team

Comments

@longchuan
Copy link
Contributor

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

@longchuan longchuan added Bug Needs Triage Needs to be assigned by the team labels Nov 4, 2024
@wuzhiming wuzhiming assigned yufengctbu and unassigned wuzhiming Nov 5, 2024
@wuzhiming
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Needs Triage Needs to be assigned by the team
Projects
None yet
Development

No branches or pull requests

3 participants