1

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?

halfer
  • 19,824
  • 17
  • 99
  • 186
Saty
  • 2,563
  • 3
  • 37
  • 88
  • You should use the number formatter to convert the number to a string, not the other way around. – Currently you are doing Float -> String -> NSNumber -> Float. – Martin R Nov 30 '16 at 12:20
  • Btw, `1.34597e+08` would be `134597000`, not `1.34597`. – Martin R Nov 30 '16 at 12:23
  • Or use NSByteCountFormatter. – Martin R Nov 30 '16 at 12:24
  • Actually 1.34597e+08 is 134597000.0 let s = 1.34597e+08 print(s)-->134597000.0 ...Returning normal Decimal already ...do i missing something ...here – Shekhu Nov 30 '16 at 12:26

0 Answers0