jpsim / Yams

A Sweet and Swifty YAML parser.
https://jpsim.com/Yams
MIT License
1.12k stars 144 forks source link

The problem with encoding floating points #384

Closed SpectralDragon closed 1 year ago

SpectralDragon commented 1 year ago

When I encoding object using YAMLEncoder, then I got a next result

    Transform:
      rotation:
        x: 0e+0
        y: 0e+0
        z: 0e+0
        w: 1e+0
      scale:
        x: 1e+0
        y: 1e+0
        z: 1e+0
      position: {}
      _matrix:
        x:
          x: 1e+0
        y:
          y: 1e+0
        z:
          z: 1e+0
        w:
          w: 1e+0

My rotation, scale and position object contains a zero values. I don't want to see these not human readable values in yaml file. When I use a JSONEncoder, all values represents correctly.

How can I fix that? In YAMLEncoder I can't find options for that.

SpectralDragon commented 1 year ago

Yeah, I got a reason. Yams use a scientific notation for scalars.

Currently it doesn't affect me a lot, but I will be glad to have control on it. I think that the issue is solved for me