We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
Swift 5.0
md5: e20ec7a1e322c9f209b388883b194590
Issue Description:
When encode a codable to json string, the double value is changed to a long decimal value.
JSONDecoder works fine!
Decimal is working fine!
// Swift 5.0 var json = "{ \"value\": 3.58, \"amount\": 3.58 }" struct Model: Codable { var value: Decimal? var amount: Double? } let data = json.data(using: .utf8) let jsonDecoder = JSONDecoder() let model = try? jsonDecoder.decode(Model.self, from: data!) let value: Decimal = model?.value ?? 0 let amount: Double = model?.amount ?? 0 print(value) print(amount) print(String(describing: model)) let encoder = JSONEncoder() encoder.outputFormatting = .prettyPrinted let newData = try? encoder.encode(model) print(String(data: newData!, encoding: .utf8)!)
print out
{
"value" : 3.58,
"amount" : 3.5800000000000001
}
The text was updated successfully, but these errors were encountered:
cc @itaiferber
Sorry, something went wrong.
Comment by Ben D. Jones (JIRA)
@swift-cisync
@swift-ci sync
No branches or pull requests
Environment
Swift 5.0
Additional Detail from JIRA
md5: e20ec7a1e322c9f209b388883b194590
Issue Description:
When encode a codable to json string, the double value is changed to a long decimal value.
JSONDecoder works fine!
Decimal is working fine!
print out
{
"value" : 3.58,
"amount" : 3.5800000000000001
}
The text was updated successfully, but these errors were encountered: