A structure representing a base-10 number.
SDKs
- iOS 2.0+
- macOS 10.0+
- Mac Catalyst 13.0+
- tvOS 9.0+
- watchOS 2.0+
Framework
- Foundation
Declaration
struct Decimal
A structure representing a base-10 number.
SDKs
Framework
struct Decimal
init()
Creates a decimal initialized to 0
.
init(sign: Floating Point Sign, exponent: Int, significand: Decimal)
Creates a decimal initialized with the given sign, exponent, and significand.
init(_exponent: Int32, _length: UInt32, _is Negative: UInt32, _is Compact: UInt32, _reserved: UInt32, _mantissa: (UInt16, UInt16, UInt16, UInt16, UInt16, UInt16, UInt16, UInt16))
Creates a decimal initialized according to the provided characteristics.
init(Double)
Creates and initializes a decimal with the provided floating point value.
init(float Literal: Double)
Creates and initializes a decimal with the provided floating point value.
init?<T>(exactly: T)
Creates a new decimal value exactly representing the provided integer.
init(Int)
Creates and initializes a decimal with the provided integer value.
init(Int8)
Creates and initializes a decimal with the provided integer value.
init(Int16)
Creates and initializes a decimal with the provided integer value.
init(Int32)
Creates and initializes a decimal with the provided integer value.
init(Int64)
Creates and initializes a decimal with the provided integer value.
init(integer Literal: Int)
Creates and initializes a decimal with the provided integer value.
init(UInt)
Creates and initializes a decimal with the provided unsigned integer value.
init(UInt8)
Creates and initializes a decimal with the provided unsigned integer value.
init(UInt16)
Creates and initializes a decimal with the provided unsigned integer value.
init(UInt32)
Creates and initializes a decimal with the provided unsigned integer value.
init(UInt64)
Creates and initializes a decimal with the provided unsigned integer value.
init(sign Of: Decimal, magnitude Of: Decimal)
Creates and initializes a decimal with the sign and magnitude of the given decimals.
func NSDecimal Copy(Unsafe Mutable Pointer<Decimal>, Unsafe Pointer<Decimal>)
Copies the value of a decimal number.
func NSDecimal String(Unsafe Pointer<Decimal>, Any?) -> String
Returns a string representation of the decimal value appropriate for the specified locale.
static func * (Decimal, Decimal) -> Decimal
Multiplies two decimal numbers.
static func *= (inout Decimal, Decimal)
Multiplies two decimal numbers, storing the result in the first number.
static func + (Decimal, Decimal) -> Decimal
Adds two decimal numbers.
static func += (inout Decimal, Decimal)
Adds two decimal numbers, storing the result in the first number.
static func - (Decimal, Decimal) -> Decimal
Subtracts one decimal number from another.
static func -= (inout Decimal, Decimal)
Subtracts one decimal number from another, storing the result in the first number.
static func / (Decimal, Decimal) -> Decimal
Divides one decimal number by another.
static func /= (inout Decimal, Decimal)
Divides one decimal number by another, storing the result in the first number.
func pow(Decimal, Int) -> Decimal
Returns a decimal number raised to a given power.
func negate()
Negates this decimal.
func NSDecimal Compact(Unsafe Mutable Pointer<Decimal>)
Compacts the decimal structure for efficiency.
func NSDecimal Multiply By Power Of10(Unsafe Mutable Pointer<Decimal>, Unsafe Pointer<Decimal>, Int16, NSDecimal Number .Rounding Mode) -> NSDecimal Number .Calculation Error
Multiplies a decimal by the specified power of 10.
func NSDecimal Round(Unsafe Mutable Pointer<Decimal>, Unsafe Pointer<Decimal>, Int, NSDecimal Number .Rounding Mode)
Rounds off the decimal value.
func NSDecimal Power(Unsafe Mutable Pointer<Decimal>, Unsafe Pointer<Decimal>, Int, NSDecimal Number .Rounding Mode) -> NSDecimal Number .Calculation Error
Raises the decimal value to the specified power.
func NSDecimal Normalize(Unsafe Mutable Pointer<Decimal>, Unsafe Mutable Pointer<Decimal>, NSDecimal Number .Rounding Mode) -> NSDecimal Number .Calculation Error
Normalizes the internal format of two decimal numbers to simplify later operations.
typealias Decimal .Rounding Mode
An alias for an enumeration that specifies possible rounding modes.
enum NSDecimal Number .Rounding Mode
These constants specify rounding behaviors.
typealias Decimal .Calculation Error
An alias for a type that specifies possible calculation errors.
enum NSDecimal Number .Calculation Error
Calculation error constants used to describe an error in exception
.
var sign: Floating Point Sign
The sign of the decimal.
var exponent: Int
The exponent of the decimal.
var significand: Decimal
The significand of the decimal.
var magnitude: Decimal
The magnitude of this decimal.
var floating Point Class: Floating Point Classification
The IEEE 754 class of this type.
var is Canonical: Bool
A Boolean value indicating whether the representation of this decimal is canonical.
var is Finite: Bool
A Boolean value indicating whether this decimal is zero, subnormal, or normal (not infinity or NaN).
var is Infinite: Bool
A Boolean value indicating whether this decimal is infinity.
var is Na N: Bool
A Boolean value indicating whether this decimal is NaN.
var is Normal: Bool
A Boolean value indicating whether this decimal is normal (not zero, subnormal, infinity, or NaN).
var is Sign Minus: Bool
A Boolean value indicating whether this decimal has a negative sign.
var is Signaling: Bool
A Boolean value indicating whether this decimal is a signaling NaN.
var is Signaling Na N: Bool
A Boolean value indicating whether this decimal is a signaling NaN.
var is Subnormal: Bool
A Boolean value indicating whether this decimal is subnormal.
var is Zero: Bool
A Boolean value indicating whether this value is zero.
var next Down: Decimal
The greatest representable value that is less than this decimal.
var next Up: Decimal
The least representable value that is greater than this decimal.
var ulp: Decimal
The unit in the last place of the decimal.
static let greatest Finite Magnitude: Decimal
The decimal that contains the largest possible non-infinite magnitude for the underlying representation.
static let least Finite Magnitude: Decimal
The decimal that contains the smallest possible non-infinite magnitude for the underlying representation.
static let least Nonzero Magnitude: Decimal
The decimal value that represents the smallest possible non-zero value for the underlying representation.
static let least Normal Magnitude: Decimal
The decimal value that represents the smallest possible normal magnitude for the underlying representation.
static let pi: Decimal
The mathematical constant pi.
static var nan: Decimal
The value that represents "not a number."
static var quiet Na N: Decimal
A quiet representation of not-a-number.
static var radix: Int
The radix used by decimal numbers.
var NSDecimal Max Size: Int32
The maximum size of Decimal
.
var NSDecimal No Scale: Int32
Specifies that the number of digits allowed after the decimal separator in a decimal number should not be limited.
static func < (Decimal, Decimal) -> Bool
Returns a Boolean value indicating whether one decimal number is strictly less than another.
static func == (Decimal, Decimal) -> Bool
Returns a Boolean value indicating whether two decimal numbers are equal.
func is Equal(to: Decimal) -> Bool
Indicates whether this decimal is equal to the specified one.
func is Less(than: Decimal) -> Bool
Indicates whether this decimal is less than the specified one.
func is Less Than Or Equal To(Decimal) -> Bool
Indicates whether this decimal is less than or equal to the specified one.
func is Totally Ordered(below Or Equal To: Decimal) -> Bool
Returns a Boolean value indicating whether this instance should precede the given value in an ascending sort.
func distance(to: Decimal) -> Decimal
Returns the distance from this value to the specified value.
func advanced(by: Decimal) -> Decimal
Returns a new value advanced by the given distance.
func NSDecimal Compare(Unsafe Pointer<Decimal>, Unsafe Pointer<Decimal>) -> Comparison Result
Compares two decimal values.
func encode(to: Encoder)
Encodes this decimal value into the given encoder.
init(from: Decoder)
Creates a new decimal value by decoding from the given decoder.
var description: String
A textual description of the decimal.
var hash Value: Int
The computed hash value for the decimal.
class NSDecimal Number
An object for representing and performing arithmetic on base-10 numbers that bridges to Decimal
; use NSDecimal
when you need reference semantics or other Foundation-specific behavior.
struct Int
A signed integer value type.
struct Double
A double-precision, floating-point value type.
class Number Formatter
A formatter that converts between numeric values and their textual representations.