init(string:locale:)
Initializes a decimal number so that its value is equivalent to that in a given numeric string, interpreted using a given locale.
Declaration
convenience init(string numberValue: String?, locale: Any?)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. - locale:
A dictionary that defines the locale (specifically the Decimalseparator) to use to interpret the number in
numberValue.
Discussion
The locale parameter determines whether the decimalSeparator is a period (like in the United States) or a comma (like in France).
The following strings show examples of acceptable values for numberValue:
2500.6(or2500,6, depending on locale)–2500.6(or–2500,6)–2.5006e3(or–2,5006e3)–2.5006E3(or–2,5006E3)
The following strings are unacceptable:
2,500.62500 3/52.5006x10e3two thousand five hundred and six tenths