Skip to content

Doubles end up in exponential notation #279

@dominikmayer

Description

@dominikmayer

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions