init(string:)
Initializes a decimal number so that its value is equivalent to that in a given numeric string.
Declaration
convenience init(string numberValue: String?)Parameters
- numberValue:
A numeric string.
Besides digits,
numberValuecan include an initial+or–; a singleEore, to indicate the exponent of a number in scientific notation; and a single decimal separator character to divide the fractional from the integral part of the number. For a listing of acceptable and unacceptable strings, see Init(string:locale:).
Discussion
Don’t use this initializer if numberValue has a fractional part, since the lack of a locale makes handling the decimal separator ambiguous. The separator is a period in some locales (like in the United States) and a comma in others (such as France).
To parse a numeric string with a fractional part, use init(string:locale:) instead. When working with numeric representations with a known format, pass a fixed locale to ensure consistent results independent of the user’s current device settings. For localized parsing that uses the user’s current device settings, pass current.