Skip to content
This repository has been archived by the owner on Mar 23, 2021. It is now read-only.

Incorrect parsing of Double values if the fraction part starts with zeroes #58

Closed
vzsg opened this issue Dec 4, 2016 · 0 comments
Closed

Comments

@vzsg
Copy link
Contributor

vzsg commented Dec 4, 2016

Consider the following JSON with three double values: [0.608, 0.0608, 0.00608]. When parsed with Jay, the resulting array contains 0.608 three times, so the scale is completely lost.

In other words:

import Jay

let testData = Array("[0.608, 0.0608, 0.00608]".utf8)

let jay = Jay()
let json = try jay.anyJsonFromData(testData)
print(json) // [0.60799999999999998, 0.60799999999999998, 0.60799999999999998]

After some investigation, the culprit is NumberParser.swift:202, where the collected fractional digits are naively converted to an integer. For example when parsing the third number, the digs array ["0", "0", "6", "0", "8"] becomes 608, losing the two initial zeroes.

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

No branches or pull requests

1 participant