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

Incorrect behavior of console.log("%d", 1.1) in Node.js #48238

Open
OguzhanUmutlu opened this issue May 29, 2023 · 3 comments
Open

Incorrect behavior of console.log("%d", 1.1) in Node.js #48238

OguzhanUmutlu opened this issue May 29, 2023 · 3 comments
Labels
confirmed-bug Issues with confirmed bugs. console Issues and PRs related to the console subsystem.

Comments

@OguzhanUmutlu
Copy link

Version

v19.8.1

Platform

Microsoft Windows NT 10.0.22621.0 x64

Subsystem

No response

What steps will reproduce the bug?

Open a Node.js environment or run a Node.js script.
Execute the following line of code: console.log("%d", 1.1);

How often does it reproduce? Is there a required condition?

The bug reproduces consistently with the given steps. The bug occurs in the Node.js runtime environment.

What is the expected behavior? Why is that the expected behavior?

According to the documentation of console.log and the JavaScript specification, the expected behavior is to log the value 1 when using the format specifier %d. The %d specifier is intended for printing integers, and it should be rounding it down.

What do you see instead?

Instead of printing 1, the Node.js environment logs 1.1

Additional information

The documentation of the console object in JavaScript, specifically on the Mozilla Developer Network (MDN), states that the %d specifier should be used to display integers. According to the documentation, it should result in rounding or truncation of floating-point numbers.

Reference: MDN - Using string substitutions
The incorrect behavior of console.log("%d", 1.1) in Node.js suggests a deviation from the expected behavior outlined in the documentation.

@MoLow MoLow added the console Issues and PRs related to the console subsystem. label May 29, 2023
@MoLow
Copy link
Member

MoLow commented May 29, 2023

Spec is here https://console.spec.whatwg.org/#formatter

@kvakil kvakil added the confirmed-bug Issues with confirmed bugs. label May 29, 2023
@joshuapare
Copy link

Can I take this? Feel free to assign to me.

@Mesteery
Copy link
Contributor

Of course, go ahead!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
confirmed-bug Issues with confirmed bugs. console Issues and PRs related to the console subsystem.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants