Skip to content

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

Closed as not planned
@OguzhanUmutlu

Description

@OguzhanUmutlu

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    confirmed-bugIssues with confirmed bugs.consoleIssues and PRs related to the console subsystem.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions