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

Closed
Rus1130 opened this issue Feb 18, 2025 · 3 comments
Closed

Code works in browser but not in node #4546

Rus1130 opened this issue Feb 18, 2025 · 3 comments
Labels
needs more info issues that need more info from the author

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"?

@avivkeller
Copy link
Member

Hi, @Rus1130! As @ljharb mentioned above, it's hard to tell what you are referring to when you say "it doesn't work" in Node.js.

From what I can tell, both the browser and in Node.js, the same result of the function is achieved. Could you elaborate a bit more on the issue?

@avivkeller avivkeller added the needs more info issues that need more info from the author label Mar 18, 2025
@avivkeller
Copy link
Member

No response from OP

@avivkeller avivkeller closed this as not planned Won't fix, can't repro, duplicate, stale Apr 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs more info issues that need more info from the author
Projects
None yet
Development

No branches or pull requests

4 participants
@ljharb @avivkeller @Rus1130 and others