Convert Double to Scientific Notation in swift
问题 I am trying to convert a given double into scientific notation, and running into some problems. I cant seem to find much documentation on how to do it either. Currently I am using: var val = 500 var numberFormatter = NSNumberFormatter() numberFormatter.numberStyle = NSNumberFormatterStyle.ScientificStyle let number = numberFormatter.numberFromString("\(val)") println(number as Double?) // Prints optional(500) instead of optional(5e+2) What am I doing wrong? 回答1: You can set NumberFormatter