Structure
Decimal
iOS 8.0+
iPadOS 8.0+
Mac Catalyst 8.0+
macOS 10.10+
tvOS 9.0+
watchOS 2.0+
A structure representing a base-10 number.
struct Decimal
Topics
Structures
struct FormatStyleA structure that converts between decimal values and their textual representations.struct ParseStrategyA parse strategy for creating decimal values from formatted strings.
Operators
static func / (Decimal, Decimal) -> DecimalDivides one decimal number by another.static func /= (inout Decimal, Decimal)Divides one decimal number by another, storing the result in the first number.
Initializers
init()Creates a decimal initialized to0.init(_:)Creates and initializes a decimal with the provided floating point value.init(_:format:lenient:)init<S>(S.ParseInput, strategy: S) throwsInitialize an instance by parsingvaluewith the givenstrategy.init(sign: FloatingPointSign, exponent: Int, significand: Decimal)Creates a decimal initialized with the given sign, exponent, and significand.init(signOf: Decimal, magnitudeOf: Decimal)Creates and initializes a decimal with the sign and magnitude of the given decimals.init?(string: String, locale: Locale?)Creates and initializes a decimal by parsing a string according to the provided locale’s conventions.
Instance Properties
var exponent: IntThe exponent of the decimal.var floatingPointClass: FloatingPointClassificationThe IEEE 754 class of this type.var isCanonical: BoolA Boolean value indicating whether the representation of this decimal is canonical.var isFinite: BoolA Boolean value indicating whether this decimal is zero, subnormal, or normal (not infinity or NaN).var isInfinite: BoolA Boolean value indicating whether this decimal is infinity.var isNaN: BoolA Boolean value indicating whether this decimal is NaN.var isNormal: BoolA Boolean value indicating whether this decimal is normal (not zero, subnormal, infinity, or NaN).var isSignMinus: BoolA Boolean value indicating whether this decimal has a negative sign.var isSignaling: BoolA Boolean value indicating whether this decimal is a signaling NaN.var isSignalingNaN: BoolA Boolean value indicating whether this decimal is a signaling NaN.var isSubnormal: BoolA Boolean value indicating whether this decimal is subnormal.var isZero: BoolA Boolean value indicating whether this value is zero.var nextDown: DecimalThe greatest representable value that is less than this decimal.var nextUp: DecimalThe least representable value that is greater than this decimal.var sign: FloatingPointSignThe sign of the decimal.var significand: DecimalThe significand of the decimal.var ulp: DecimalThe unit in the last place of the decimal.
Instance Methods
func formatted() -> StringFormats the decimal using a default localized format style.func formatted<S>(S) -> S.FormatOutputFormats the decimal using the provided format style.func isEqual(to: Decimal) -> BoolIndicates whether this decimal is equal to the specified one.func isLess(than: Decimal) -> BoolIndicates whether this decimal is less than the specified one.func isLessThanOrEqualTo(Decimal) -> BoolIndicates whether this decimal is less than or equal to the specified one.func isTotallyOrdered(belowOrEqualTo: Decimal) -> BoolReturns a Boolean value indicating whether this instance should precede the given value in an ascending sort.
Type Properties
static let greatestFiniteMagnitude: DecimalThe decimal that contains the largest possible non-infinite magnitude for the underlying representation.static let leastFiniteMagnitude: DecimalThe decimal that contains the smallest possible non-infinite magnitude for the underlying representation.static let leastNonzeroMagnitude: DecimalThe decimal value that represents the smallest possible non-zero value for the underlying representation.static let leastNormalMagnitude: DecimalThe decimal value that represents the smallest possible normal magnitude for the underlying representation.static var nan: DecimalThe value that represents “not a number.”static let pi: DecimalThe mathematical constant pi.static var quietNaN: DecimalA quiet representation of not-a-number.static var radix: IntThe radix used by decimal numbers.
Enumerations
enum CalculationErrorAn enumeration that specifies possible calculation errors.enum RoundingModeAn enumeration that specifies possible rounding modes.
Default Implementations
- AdditiveArithmetic Implementations
- Comparable Implementations
- CustomStringConvertible Implementations
- Decodable Implementations
- Encodable Implementations
- Equatable Implementations
- ExpressibleByFloatLiteral Implementations
- ExpressibleByIntegerLiteral Implementations
- Hashable Implementations
- Numeric Implementations
- SignedNumeric Implementations
- Strideable Implementations
Relationships
Conforms To
Swift.AdditiveArithmeticSwift.ComparableSwift.CopyableSwift.CustomStringConvertibleSwift.DecodableSwift.EncodableSwift.EquatableSwift.EscapableSwift.ExpressibleByFloatLiteralSwift.ExpressibleByIntegerLiteralSwift.HashableSwift.NumericSwift.SendableSwift.SendableMetatypeSwift.SignedNumericSwift.Strideable