goccy / go-yaml

YAML support for the Go language
MIT License
1.12k stars 129 forks source link

Small float values can't be decoded after an unmarshal-marshal round trip #458

Closed cooscoos closed 1 month ago

cooscoos commented 2 months ago

Describe the bug Take a small float value in yaml, e.g.:

value: 0.00001

then:

  1. unmarshal it from yaml to a map[string]interface{}
  2. marshal that map back into a new yaml.

That new yaml now cannot be decoded because the unmarshal + marshal step changes value from 0.00001 to 1e-05.

1e-05 is interpreted by the final decoder as a string.

To Reproduce

Playground example: https://go.dev/play/p/mxsL_Dp_naC

This issue affects values of 0.00001 (1e-05) or lower. Larger values (e.g. 0.0001, 10000000000) are fine.

Expected behavior Unmarshal-marshal should result in yaml that a decoder can parse.

Version Variables