Skip to content

JSONSerialization works differently on platforms #5173

Open
@Ildarec11

Description

@Ildarec11

If you run the following code on macOS, the output will be 68.31999999999999:

let jsonString = """
{
    "amount": 68.32
}

let json = jsonString.data(using: .utf8)!
let serialized = try JSONSerialization.jsonObject(with: json) as! [String: Any]

let amount = serialized["amount"]
print(amount)

However, if you run the same code on SwiftFiddle (using the x86_64-unknown-linux-gnu platform), the output will be 68.32.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions