简体   繁体   中英

How to not use ScientificStyle with CGFloat?

I want to convert a String to CGFloat but because of the String is too long, the converted number is formatted with the ScientificStyle.

How can I avoid this?

The one I want: 10153414864354680

The one I get: 1.01534148643547e+16

Code

CGFloat(NSNumberFormatter().numberFromString(str)

Thanks

The converted number (ie, the CGFloat ) does not have a style. You only see the style when you print it or otherwise try and display it and it implicitly converts it into a String . You should use an NSNumberFormatter to convert it back to a String to display.

print("Value: \(NSNumberFormatter().stringFromNumber(<#Some CGFloat#>))")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM