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

[Swift] Very large numbers are not converted to string correctly #8188

Open
joeboyscout04 opened this issue May 15, 2018 · 0 comments
Open

Comments

@joeboyscout04
Copy link
Contributor

joeboyscout04 commented May 15, 2018

Description

When working with very large numbers (in this case, timestamps in nanoseconds), the default printing by swift results in an exponent character in the string. For example:

let largeNumber: Double = 1.52639622817888e+16
print("\(largeNumber)") // results in "1.52639622817888e+16"
Swagger-codegen version

2.3.1

Steps to reproduce

This is reproducible in an Swift project that uses Doubles for request parameters, as long as the input Double is sufficiently large.

Related issues/PRs

TBD

Suggest a fix/enhancement

Proposed fix is to switch to using NumberFormatter()

let formatter = NumberFormatter()
let num = NSNumber(value: bigNumber)

print(formatter.string(from: num)) // results in "15263962281788800"

@joeboyscout04 joeboyscout04 mentioned this issue May 15, 2018
4 tasks
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

No branches or pull requests

1 participant