Skip to content
mattt edited this page Oct 30, 2020 · 6 revisions

Money

An amount of money in a given currency.

public struct Money<Currency: CurrencyType>: Equatable, Hashable

Inheritance

Codable, Comparable, CustomStringConvertible, Equatable, ExpressibleByFloatLiteral, ExpressibleByIntegerLiteral, ExpressibleByStringLiteral, Hashable, LosslessStringConvertible

Initializers

init(_:)

Creates an amount of money with a given decimal number.

public init(_ amount: Decimal)

init?(_:)

public init?(_ description: String)

init(integerLiteral:)

public init(integerLiteral value: Int)

init(floatLiteral:)

Creates a new value from the given floating-point literal.

public init(floatLiteral value: Double)

init(unicodeScalarLiteral:)

public init(unicodeScalarLiteral value: Unicode.Scalar)

init(extendedGraphemeClusterLiteral:)

public init(extendedGraphemeClusterLiteral value: Character)

init(stringLiteral:)

public init(stringLiteral value: String)

init(from:)

public init(from decoder: Decoder) throws

Properties

amount

The amount of money.

var amount: Decimal

currency

The currency type.

var currency: CurrencyType.Type

rounded

A monetary amount rounded to the number of places of the minor currency unit.

var rounded: Money<Currency>

description

var description: String

Methods

<(lhs:rhs:)

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

+(lhs:rhs:)

The sum of two monetary amounts.

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

+=(lhs:rhs:)

Adds one monetary amount to another.

public static func +=(lhs: inout Money<Currency>, rhs: Money<Currency>)

-(lhs:rhs:)

The difference between two monetary amounts.

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

-=(lhs:rhs:)

Subtracts one monetary amount from another.

public static func -=(lhs: inout Money<Currency>, rhs: Money<Currency>)

-(value:)

Subtracts one monetary amount from another.

public static prefix func -(value: Money<Currency>) -> Money<Currency>

*(lhs:rhs:)

The product of a monetary amount and a scalar value.

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

*(lhs:rhs:)

The product of a monetary amount and a scalar value.

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

*(lhs:rhs:)

The product of a monetary amount and a scalar value.

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

*(lhs:rhs:)

The product of a monetary amount and a scalar value.

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

*(lhs:rhs:)

The product of a monetary amount and a scalar value.

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

*(lhs:rhs:)

The product of a monetary amount and a scalar value.

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

*=(lhs:rhs:)

Multiplies a monetary amount by a scalar value.

public static func *=(lhs: inout Money<Currency>, rhs: Decimal)

*=(lhs:rhs:)

Multiplies a monetary amount by a scalar value.

public static func *=(lhs: inout Money<Currency>, rhs: Double)
   Multiplies a monetary amount by a scalar value.

   - Important: Multiplying a monetary amount by a floating-point number
                results in an amount rounded to the number of places
                of the minor currency unit.
                To produce a smaller fractional monetary amount,
                multiply by a `Decimal` value instead.

*=(lhs:rhs:)

Multiplies a monetary amount by a scalar value.

public static func *=(lhs: inout Money<Currency>, rhs: Int)

encode(to:)

public func encode(to encoder: Encoder) throws
Clone this wiki locally