Skip to content
This repository was archived by the owner on Jan 17, 2024. It is now read-only.
hallee edited this page May 10, 2020 · 1 revision

Money

Money is a precise representation of a currency value.

public struct Money: Hashable

For even dollar amounts, you can initialize this type with an integer literal:

let price: Money = 100

For dollars and cents, use the string literal initializer instead:

let price: Money = "100.12"

Swift’s Decimal type loses precision when initialized via a float literal and encoding to JSON. See this discussion for more details. Enforcing the use of the string literal initializer ensures complete precision when dealing with money values.

Inheritance

AdditiveArithmetic, Codable, Comparable, CustomDebugStringConvertible, CustomStringConvertible, ExpressibleByIntegerLiteral, ExpressibleByStringLiteral, Hashable, Numeric

Initializers

init(_:)

init(_ value: Decimal)

init(stringLiteral:)

public init(stringLiteral value: String)

init(integerLiteral:)

public init(integerLiteral value: Int)

init(from:)

public init(from decoder: Decoder) throws

init?(exactly:)

public init?<T>(exactly source: T) where T: BinaryInteger

Properties

value

let value: Decimal

description

var description: String

debugDescription

var debugDescription: String

magnitude

var magnitude: Money

Methods

encode(to:)

public func encode(to encoder: Encoder) throws

<(lhs:rhs:)

public static func <(lhs: Money, rhs: Money) -> Bool

+(lhs:rhs:)

public static func +(lhs: Money, rhs: Money) -> Money

-(lhs:rhs:)

public static func -(lhs: Money, rhs: Money) -> Money

*(lhs:rhs:)

public static func *(lhs: Money, rhs: Money) -> Money

/(lhs:rhs:)

public static func /(lhs: Money, rhs: Money) -> Money

*=(lhs:rhs:)

public static func *=(lhs: inout Money, rhs: Money)

/=(lhs:rhs:)

public static func /=(lhs: inout Money, rhs: Money)
Clone this wiki locally