Initializer

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

numericString

A numeric string.

Besides digits, numericString can include an initial + or ; a single E or e, 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 numericString.

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 numericString:

  • 2500.6 (or 2500,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.6

  • 2500 3/5

  • 2.5006x10e3

  • two thousand five hundred and six tenths

See Also

Initializing a Decimal Number

init(decimal: Decimal)

Initializes a decimal number to represent a given decimal.

init(mantissa: UInt64, exponent: Int16, isNegative: Bool)

Initializes a decimal number using the given mantissa, exponent, and sign.

init(string: String?)

Initializes a decimal number so that its value is equivalent to that in a given numeric string.

Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

Learn more about using Apple's beta software