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

Code works in browser but not in node #4546

Open
Rus1130 opened this issue Feb 18, 2025 · 1 comment
Open

Code works in browser but not in node #4546

Rus1130 opened this issue Feb 18, 2025 · 1 comment

Comments

@Rus1130
Copy link

Rus1130 commented Feb 18, 2025

I have this code, which is used to limit the amount of characters after a string of zeros. It works fine in the browser, but in node.js it doesn't work at all.

function stringifyNumber(num, zero_n) {
    let strNum = num.toString();
    let  [intPart, decPart] = strNum.split(".");

    if (!decPart) return num;

    let result = intPart + ".";
    let foundZero = false;
    let pushAllNumbers = true;
    let pushCount = zero_n;

    for (let i = 0; i < decPart.length; i++) {
        let digit = decPart[i];

        if(digit === "0") foundZero = true;
        if(pushAllNumbers) result += digit;

        if(decPart[i + 1] !== "0" && foundZero) {
            pushAllNumbers = false;
        }

        if(!pushAllNumbers) {
            if(pushCount > 0) {
                result += digit;
                pushCount--;
            }

            if(digit === '0') pushCount = zero_n;
        }
        
    }

    return result;
}
@github-project-automation github-project-automation bot moved this to 📋 Backlog in Node.js Website Feb 18, 2025
@ljharb ljharb transferred this issue from nodejs/nodejs.org Feb 18, 2025
@ljharb
Copy link
Member

ljharb commented Feb 18, 2025

what constitutes "works" or "doesn't work"?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: 📋 Backlog
Development

No branches or pull requests

2 participants