Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // StorjToken is the currency for the STORJ ERC20 token, which powers // most payments on the current Storj network. StorjToken = NewCurrency("STORJ Token", "STORJ", 8) // USDollars is the currency of United States dollars, where fractional // cents are not supported. USDollars = NewCurrency("US dollars", "USD", 2) // Bitcoin is the currency for the well-known cryptocurrency Bitcoin // (a.k.a. BTC). Bitcoin = NewCurrency("Bitcoin (BTC)", "BTC", 8) // LiveGoats is the currency of live goats, which some Storj network // satellites may elect to support for payments. LiveGoats = NewCurrency("Live goats", "goats", 0) // Error is a class of errors encountered in the monetary package. Error = errs.Class("monetary error") )
Functions ¶
Types ¶
type Amount ¶
type Amount struct {
// contains filtered or unexported fields
}
Amount represents a monetary amount, encapsulating a value and a currency.
The value of the Amount is represented in "base units", meaning units of the smallest indivisible portion of the given currency. For example, when the currency is USDollars, the base unit would be cents.
func AmountFromBaseUnits ¶
AmountFromBaseUnits creates a new Amount instance from the given count of base units and in the given currency.
func AmountFromBigFloat ¶
AmountFromBigFloat creates a new Amount instance from the given floating point value and in the given currency. The big.Float is expected to give the value of the amount in currency units.
func AmountFromDecimal ¶
AmountFromDecimal creates a new Amount instance from the given decimal value and in the given currency. The decimal value is expected to be in currency units.
Example:
AmountFromDecimal(decimal.NewFromFloat(3.50), USDollars) == Amount{baseUnits: 350, currency: USDollars}
func AmountFromString ¶
AmountFromString creates a new Amount instance from the given base 10 value and in the given currency. The string is expected to give the value of the amount in currency units.
func (Amount) AsBigFloat ¶
AsBigFloat returns the monetary value in currency units expressed as an instance of *big.Float with precision=64. _Warning_ may lose precision!
func (Amount) AsBigFloatWithPrecision ¶
AsBigFloatWithPrecision returns the monetary value in currency units expressed as an instance of *big.Float with the given precision. _Warning_ this may lose precision if the specified precision is not large enough!
func (Amount) AsDecimal ¶
AsDecimal returns the monetary value in currency units expressed as an arbitrary precision decimal number.
func (Amount) AsFloat ¶
AsFloat returns the monetary value in currency units expressed as a floating point number. _Warning_ may lose precision! (float64 has the equivalent of 53 bits of precision, as defined by big.Float.)
type Currency ¶
type Currency struct {
// contains filtered or unexported fields
}
Currency represents a currency for the purpose of representing amounts in that currency. Currency instances have a name, a symbol, and a number of supported decimal places of supported precision.
func NewCurrency ¶
NewCurrency creates a new Currency instance.