Documentation ¶
Index ¶
- func URL(from, to string) string
- type Amount
- type Currency
- func (c Currency) Amount(value decimal.Decimal) Amount
- func (c Currency) AmountFromFloat(value float64) Amount
- func (c Currency) AmountFromString(value string) (Amount, error)
- func (c Currency) ExchangeRate(target Currency) (decimal.Decimal, error)
- func (c Currency) ExchangeRateFloat(target Currency) (rate float64, exact bool, err error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Amount ¶
Amount represents a money value in a given currency.
func NewAmount ¶
NewAmount returns an Amount with the given value and currency. It's sort of a helper function, making the creation of an Amount simpler.
func NewAmountFromFloat ¶
NewAmountFromFloat returns an Amount with the given value (provided as float) and currency. It's sort of a helper function, making the creation of an Amount from a float simpler.
func NewAmountFromString ¶
NewAmountFromString tries creating a new amount from the provided string. Should the conversion fail, an error is returned. If the conversion was successful, the function returns the new Amount.
func (Amount) ConvertTo ¶
ConvertTo converts Amount a to another target currency. It returns the converted value as a float64 or an error.
func (Amount) ConvertToMv ¶
ConvertToMv converts Amount a to another target currency. It returns the converted Amount or an error.
type Currency ¶
type Currency uint8
Currency reprents a currency as an integer value. This is used as sort of an enum in which the constant values defined as currencies may be used by users of the library and at the same time are used as indeces for the currency code array.
const ( // USD -> USDollar ($ / USD) USD Currency = iota // EUR -> Euro (€ / EUR) EUR // JPY -> JapaneseYen (¥ / JPY) JPY // BGN -> BulgarianLev (лв. / BGN) BGN // CZK -> CzechKoruna (Kč / CZK) CZK // DKK -> DanishKrone (kr. / DKK) DKK // GBP -> GreatBritainPound (£ / GBP) GBP // HUF -> HungarianForint (Ft / HUF) HUF // LTL -> LithuanianLitas (Lt / LTL) LTL // LVL -> LatvianLats (Ls / LVL) LVL // PLN -> PolishZloty (zł / PLN) PLN // RON -> RomanianLeu (? / RON) RON // SEK -> SwedishKrona (kr / SEK) SEK // CHF -> SwissFranc (CHF / CHF) CHF // NOK -> NorwegianKrone (kr / NOK) NOK // HRK -> CroatianKuna (kn / HRK) HRK // RUB -> RussianRubel (₽ / RUB) RUB // TRY -> TurkishLira (₺ / TRY) TRY // AUD -> AustralianDollar ($, A$ or AUD / AUD) AUD // BRL -> BrazilianReal (R$ / BRL) BRL // CAD -> CanadianDollar ($, Can$, C$ or CAD / CAD) CAD // CNY -> ChineseYuan (¥ / CNY) CNY // HKD -> HongKongDollar ($ or HK$ / HKD) HKD // IDR -> IndonesianRupiah (Rp / IDR) IDR // ILS -> IsraeliNewShekel (₪ / ILS) ILS // INR -> IndianRupee (₹ / INR) INR // KRW -> SouthKoreanWon (₩ / KRW) KRW // MXN -> MexicanPeso ($ or Mex$ / MXN) MXN // MYR -> MalaysianRinggit (RM / MYR) MYR // NZD -> NewZealandDollar ($ / NZD) NZD // PHP -> PhilippinePeso (₱ / PHP) PHP // SGD -> SingaporeDollar (S$ or $ / SGD) SGD // THB -> ThaiBaht (฿ / THB) THB // ZAR -> SouthAfricanRand (R / ZAR) ZAR // ISK -> IcelandicKrona (kr or Íkr / ISK) ISK )
func (Currency) AmountFromFloat ¶
AmountFromFloat creates an amount for the given currency unit and a value, which is provided as a float64.
func (Currency) AmountFromString ¶
AmountFromString creates an amount for the given currency unit and a value, which is provided as a string.
func (Currency) ExchangeRate ¶
ExchangeRate returns the exchance rate when exchanging money from the currency c to the target currency or an error.