Open dominikmayer opened 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?
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.
Is there a workaround or anything for this issue?
I have the following object:
And an example textual representation:
I can decode it:
But when I try to encode it again the doubles all end up in exponential notation:
How can I encode the doubles without the exponential notation?