Skip to content

Negative zero treated inconsistently by stringify and parse #638

Closed

Description

@futpib

Describe the bug
Negative zero is preserved by parse but not preserved by stringify

To Reproduce

> YAML.parse('-0')
-0
> YAML.parse('+0')
0
> YAML.stringify(-0)
'0\n'
> YAML.stringify(+0)
'0\n'

Expected behaviour
I expect both method to either drop zero sign or to preserve it, or to have an option for this. I prefer preserve to keep parse(stringify(x)) == x.

> YAML.parse('-0')
-0
> YAML.parse('+0')
0
> YAML.stringify(-0)
'-0\n'
> YAML.stringify(+0)
'0\n'

Versions (please complete the following information):

  • Environment: node v24.6.0
  • yaml: 2.8.1

Additional context
🤷🏻

Activity

  1. added
    bug
    on Sep 12, 2025
  2. eemeli commented on Sep 13, 2025

    @eemeli
    Owner

    Huh, that's a bit surprising. Numbers are serialised with JSON.stringify(), and it does this:

    JSON.parse('-0') // -0
    JSON.stringify(-0) // '0'

    But I agree that we should special-case -0.

  3. added a commit that references this issue on Jan 10, 2026
    95285f8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions