Decimal
- iOS
- 8.0+
- macOS
- 10.10+
- tvOS
- 9.0+
- watchOS
- 2.0+
struct Decimal
struct Decimal
import FoundationEssentials
protocol AdditiveArithmetic : Equatable
A type with values that support addition and subtraction.
protocol Comparable : Equatable
A type that can be compared using the relational operators <
, <=
, >=
, and >
.
protocol Copyable
A type whose values can be implicitly or explicitly copied.
protocol CustomStringConvertible
A type with a customized textual representation.
protocol Decodable
A type that can decode itself from an external representation.
protocol Encodable
A type that can encode itself to an external representation.
protocol Equatable
A type that can be compared for value equality.
protocol Escapable
protocol ExpressibleByFloatLiteral
A type that can be initialized with a floating-point literal.
protocol ExpressibleByIntegerLiteral
A type that can be initialized with an integer literal.
protocol Hashable : Equatable
A type that can be hashed into a Hasher
to produce an integer hash value.
protocol Numeric : AdditiveArithmetic, ExpressibleByIntegerLiteral
A type with values that support multiplication.
protocol Sendable
protocol SignedNumeric : Numeric
A numeric type with a negation operation.
protocol Strideable<Stride> : Comparable
A type representing continuous, one-dimensional values that can be offset and measured.
init()
init(_ value: Double)
init(_ value: Int)
init(_ value: UInt)
init(_ value: Int8)
init(_ value: Int16)
init(_ value: Int32)
init(_ value: Int64)
init(_ value: UInt8)
init(_ value: UInt16)
init(_ value: UInt32)
init(_ value: UInt64)
init?<T>(exactly source: T) where T : BinaryInteger
init(floatLiteral value: Double)
init(from decoder: any Decoder) throws
init(integerLiteral value: Int)
init(mantissa: UInt64, exponent: Int16, isNegative: Bool)
init(sign: FloatingPointSign, exponent: Int, significand: Decimal)
init(signOf: Decimal, magnitudeOf magnitude: Decimal)
init?(string: String, locale: Locale? = nil)
static let greatestFiniteMagnitude: Decimal
static let leastFiniteMagnitude: Decimal
static let leastNonzeroMagnitude: Decimal
static let leastNormalMagnitude: Decimal
static var nan: Decimal { get }
static let pi: Decimal
static var quietNaN: Decimal { get }
static var radix: Int { get }
static func decimal(from stringView: String.UTF8View, decimalSeparator: String.UTF8View, matchEntireString: Bool) -> (result: Decimal?, processedLength: Int)
var description: String { get }
var exponent: Int { get }
var floatingPointClass: FloatingPointClassification { get }
The IEEE 754 “class” of this type.
var isCanonical: Bool { get }
var isFinite: Bool { get }
true
if self
is zero, subnormal, or normal (not infinity or NaN), false
otherwise.
var isInfinite: Bool { get }
true
if self
is infinity, false
otherwise.
var isNaN: Bool { get }
true
if self
is NaN, false
otherwise.
var isNormal: Bool { get }
true
if self
is normal (not zero, subnormal, infinity, or NaN), false
otherwise.
var isSignMinus: Bool { get }
true
if self
is negative, false
otherwise.
var isSignaling: Bool { get }
true
if self
is a signaling NaN, false
otherwise.
var isSignalingNaN: Bool { get }
true
if self
is a signaling NaN, false
otherwise.
var isSubnormal: Bool { get }
true
if self
is subnormal, false
otherwise.
var isZero: Bool { get }
true
if self
is +0.0 or -0.0, false
otherwise.
var magnitude: Decimal { get }
var nextDown: Decimal { get }
var nextUp: Decimal { get }
var sign: FloatingPointSign { get }
var significand: Decimal { get }
var ulp: Decimal { get }
static func * (lhs: Decimal, rhs: Decimal) -> Decimal
static func *= (lhs: inout Decimal, rhs: Decimal)
static func + (lhs: Decimal, rhs: Decimal) -> Decimal
static func += (lhs: inout Decimal, rhs: Decimal)
static func - (lhs: Decimal, rhs: Decimal) -> Decimal
static func -= (lhs: inout Decimal, rhs: Decimal)
static func / (lhs: Decimal, rhs: Decimal) -> Decimal
static func /= (lhs: inout Decimal, rhs: Decimal)
static func < (lhs: Decimal, rhs: Decimal) -> Bool
static func == (lhs: Decimal, rhs: Decimal) -> Bool
func advanced(by n: Decimal) -> Decimal
func distance(to other: Decimal) -> Decimal
func encode(to encoder: any Encoder) throws
func hash(into hasher: inout Hasher)
func isEqual(to other: Decimal) -> Bool
func isLess(than other: Decimal) -> Bool
func isLessThanOrEqualTo(_ other: Decimal) -> Bool
func isTotallyOrdered(belowOrEqualTo other: Decimal) -> Bool
mutating func negate()
func toString(with locale: Locale? = nil) -> String
enum CalculationError
enum RoundingMode
typealias Mantissa = (UInt16, UInt16, UInt16, UInt16, UInt16, UInt16, UInt16, UInt16)
static var zero: Self { get }
The zero value.
static func != (lhs: Self, rhs: Self) -> Bool
Returns a Boolean value indicating whether two values are not equal.
static func + (x: Self) -> Self
Returns the given number unchanged.
static func += (lhs: inout Self, rhs: Self)
static func - (operand: Self) -> Self
Returns the additive inverse of the specified value.
static func -= (lhs: inout Self, rhs: Self)
static func ... (minimum: Self) -> PartialRangeFrom<Self>
Returns a partial range extending upward from a lower bound.
static func ... (maximum: Self) -> PartialRangeThrough<Self>
Returns a partial range up to, and including, its upper bound.
static func ... (minimum: Self, maximum: Self) -> ClosedRange<Self>
Returns a closed range that contains both of its bounds.
static func ..< (maximum: Self) -> PartialRangeUpTo<Self>
Returns a partial range up to, but not including, its upper bound.
static func ..< (minimum: Self, maximum: Self) -> Range<Self>
Returns a half-open range that contains its lower bound but not its upper bound.
static func < (x: Self, y: Self) -> Bool
static func <= (lhs: Self, rhs: Self) -> Bool
Returns a Boolean value indicating whether the value of the first argument is less than or equal to that of the second argument.
static func == (x: Self, y: Self) -> Bool
static func > (lhs: Self, rhs: Self) -> Bool
Returns a Boolean value indicating whether the value of the first argument is greater than that of the second argument.
static func >= (lhs: Self, rhs: Self) -> Bool
Returns a Boolean value indicating whether the value of the first argument is greater than or equal to that of the second argument.
mutating func negate()
Replaces this value with its additive inverse.
import FoundationInternationalization
init(_ value: String, format: Decimal.FormatStyle.Percent, lenient: Bool = true) throws
init(_ value: String, format: Decimal.FormatStyle.Currency, lenient: Bool = true) throws
init(_ value: String, format: Decimal.FormatStyle, lenient: Bool = true) throws
init<S>(_ value: S.ParseInput, strategy: S) throws where S : ParseStrategy, S.ParseOutput == Decimal
Initialize an instance by parsing value
with the given strategy
.
func formatted() -> String
Format self
using Decimal.FormatStyle
func formatted<S>(_ format: S) -> S.FormatOutput where S : FormatStyle, S.FormatInput == Decimal
Format self
with the given format.
struct FormatStyle
struct ParseStrategy<Format> where Format : FormatStyle, Format.FormatInput == Decimal
import Foundation
mutating func add(_ other: Decimal)
mutating func divide(by other: Decimal)
mutating func multiply(by other: Decimal)
mutating func subtract(_ other: Decimal)