Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Doubles end up in exponential notation #279

Open
dominikmayer opened this issue Oct 14, 2020 · 2 comments · May be fixed by #374
Open

Doubles end up in exponential notation #279

dominikmayer opened this issue Oct 14, 2020 · 2 comments · May be fixed by #374

Comments

@dominikmayer
Copy link

dominikmayer commented Oct 14, 2020

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
Copy link
Owner

jpsim commented Oct 21, 2020

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
Copy link

cplr commented Jun 29, 2022

Is there a workaround or anything for this issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants