jpsim / Yams

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

Doubles end up in exponential notation #279

Open dominikmayer opened 4 years ago

dominikmayer commented 4 years ago

I have the following object:

struct Example: Codable {
    var temperature: Double
    var latitude: Double
    var longitude: Double
}

And an example textual representation:

let example = """
temperature: 3.08
latitude: 40.7580
longitude: -73.9855
"""

I can decode it:

let decoder = YAMLDecoder()
let decodedExample = try decoder.decode(Example.self, from: example)
print(decodedExample)

// Example(temperature: 3.08, latitude: 40.758, longitude: -73.9855)

But when I try to encode it again the doubles all end up in exponential notation:

let encoder = YAMLEncoder()
let encodedExample = try encoder.encode(decodedExample)
print(encodedExample)

// temperature: 3.08e+0
// latitude: 4.0758e+1
// longitude: -7.39855e+1

How can I encode the doubles without the exponential notation?

jpsim commented 4 years ago

Thanks for reporting! At first glance I’d consider this a bug. It’s possible that further investigation will surface a valid reason why this is happening.

cplr commented 2 years ago

Is there a workaround or anything for this issue?