Saty
Saty

Reputation: 2621

How to convert the exponential value to normal decimal or without exponent format in Swift?

I am getting a exponential value for the expected downloadable size in NSURLConnectionDelegate.

It's showing as 1.34597e+08.

Now I am trying to convert the value to 1.3459 using the below code, but with no luck:

    self.expectedDownloadSize = Float(response.expectedContentLength)
    let s = self.expectedDownloadSize.description

    let numberFormatter = NSNumberFormatter()
    numberFormatter.numberStyle = NSNumberFormatterStyle.DecimalStyle
    numberFormatter.maximumFractionDigits = 4
    var num = numberFormatter.numberFromString(s as String)
    self.expectedDownloadSize = num?.floatValue

How can I get the expected size of download?

Upvotes: 1

Views: 728

Answers (0)

Related Questions