Documentation ¶
Index ¶
- Constants
- Variables
- func StringIsAmount(str string, acceptInt bool) bool
- func StringIsCurrency(str string) bool
- type Amount
- func (a Amount) Abs() Amount
- func (a Amount) AbsFloat() float64
- func (ptr *Amount) AmountOr(defaultVal Amount) Amount
- func (a Amount) BigFloat() *big.Float
- func (a Amount) Cents() int64
- func (a Amount) Copysign(sign Amount) Amount
- func (a Amount) DividedByRate(rate Rate) Amount
- func (a *Amount) Equal(b *Amount) bool
- func (ptr *Amount) FloatOr(defaultVal float64) float64
- func (a Amount) Format(thousandsSep, decimalSep rune, precision int) string
- func (a Amount) GoString() string
- func (a *Amount) Invert()
- func (a Amount) Inverted() Amount
- func (a Amount) IsInf() bool
- func (a Amount) IsNaN() bool
- func (a Amount) MultipliedByRate(rate Rate) Amount
- func (a Amount) Percentage(percent float64) Amount
- func (a Amount) RoundToCents() Amount
- func (a Amount) RoundToDecimals(decimals int) Amount
- func (a Amount) RoundToInt() Amount
- func (a *Amount) ScanString(source string, validate bool) error
- func (a Amount) Signbit() bool
- func (a Amount) SplitEqually(count int) []Amount
- func (a Amount) SplitProportionally(weights []Amount) []Amount
- func (a Amount) String() string
- func (ptr *Amount) StringOr(defaultVal string) string
- func (a *Amount) UnmarshalJSON(j []byte) error
- func (a Amount) Valid() bool
- func (a Amount) ValidAndGreaterZero() bool
- func (a Amount) ValidAndHasSign(sign int) bool
- func (a Amount) ValidAndPositive() bool
- func (a Amount) ValidAndSmallerZero() bool
- func (a Amount) WithNegSign(negative bool) Amount
- func (a Amount) WithPosSign(positive bool) Amount
- type AmountParser
- type Currency
- func (c Currency) EnglishName() string
- func (c *Currency) GetOrDefault(defaultVal Currency) Currency
- func (c Currency) IsEUR() bool
- func (c Currency) Normalized() (Currency, error)
- func (c Currency) NormalizedOrNull() NullableCurrency
- func (c Currency) NullableCurrency() NullableCurrency
- func (c *Currency) Scan(value any) error
- func (c *Currency) ScanString(source string, validate bool) error
- func (c Currency) String() string
- func (c Currency) Symbol() string
- func (c Currency) Valid() bool
- func (c *Currency) ValidPtr() bool
- func (c Currency) Validate() error
- func (c Currency) Value() (driver.Value, error)
- type CurrencyAmount
- func (ca CurrencyAmount) Format(currencyFirst bool, thousandsSep, decimalSep rune, precision int) string
- func (ca CurrencyAmount) GoString() string
- func (ca *CurrencyAmount) Scan(value any) (err error)
- func (ca *CurrencyAmount) ScanString(source string, validate bool) error
- func (ca CurrencyAmount) String() string
- func (ca CurrencyAmount) Value() (driver.Value, error)
- type CurrencyAmountParser
- type CurrencyParser
- type NullableCurrency
- func (n NullableCurrency) Currency() Currency
- func (n NullableCurrency) EnglishName() string
- func (n NullableCurrency) Get() Currency
- func (n NullableCurrency) GetOr(defaultVal Currency) Currency
- func (n NullableCurrency) IsNotNull() bool
- func (n NullableCurrency) IsNull() bool
- func (n NullableCurrency) MarshalJSON() ([]byte, error)
- func (n NullableCurrency) Normalized() (NullableCurrency, error)
- func (n NullableCurrency) NormalizedOrNull() NullableCurrency
- func (n *NullableCurrency) Scan(value any) error
- func (n *NullableCurrency) ScanString(source string, validate bool) error
- func (n *NullableCurrency) Set(currency Currency)
- func (n *NullableCurrency) SetNull()
- func (n NullableCurrency) String() string
- func (n NullableCurrency) StringOr(defaultString string) string
- func (n NullableCurrency) Symbol() string
- func (n NullableCurrency) Valid() bool
- func (n NullableCurrency) ValidAndNotNull() bool
- func (n *NullableCurrency) ValidPtr() bool
- func (n NullableCurrency) Validate() error
- func (n NullableCurrency) Value() (driver.Value, error)
- type Rate
- func (r Rate) Abs() Rate
- func (r Rate) AbsFloat() float64
- func (r Rate) BigFloat() *big.Float
- func (r Rate) Copysign(sign Rate) Rate
- func (r *Rate) Equal(other *Rate) bool
- func (ptr *Rate) FloatOr(defaultVal float64) float64
- func (r Rate) Format(thousandsSep, decimalSep rune, precision int) string
- func (r Rate) GoString() string
- func (r Rate) Inverse() Rate
- func (r *Rate) Invert()
- func (r Rate) Inverted() Rate
- func (ptr *Rate) RateOr(defaultVal Rate) Rate
- func (r Rate) RoundToDecimals(decimals int) Rate
- func (r Rate) RoundToInt() Rate
- func (r *Rate) ScanString(source string, validate bool) error
- func (r Rate) Signbit() bool
- func (ptr *Rate) StringOr(defaultVal string) string
- func (r *Rate) UnmarshalJSON(j []byte) error
- func (r Rate) Valid() bool
- func (r Rate) ValidAndGreaterZero() bool
- func (r Rate) ValidAndHasSign(sign int) bool
- func (r Rate) ValidAndPositive() bool
- func (r Rate) ValidAndSmallerZero() bool
- func (r Rate) WithNegSign(negative bool) Rate
- func (r Rate) WithPosSign(positive bool) Rate
Constants ¶
const ( AED = "AED" // United Arab Emirates Dirham AFN = "AFN" // Afghanistan Afghani ALL = "ALL" // Albania Lek AMD = "AMD" // Armenia Dram ANG = "ANG" // Netherlands Antilles Guilder AOA = "AOA" // Angola Kwanza ARS = "ARS" // Argentina Peso AUD = "AUD" // Australia Dollar AWG = "AWG" // Aruba Guilder AZN = "AZN" // Azerbaijan New Manat BAM = "BAM" // Bosnia and Herzegovina Convertible Marka BBD = "BBD" // Barbados Dollar BDT = "BDT" // Bangladesh Taka BGN = "BGN" // Bulgaria Lev BHD = "BHD" // Bahrain Dinar BIF = "BIF" // Burundi Franc BMD = "BMD" // Bermuda Dollar BND = "BND" // Brunei Darussalam Dollar BOB = "BOB" // Bolivia Bolíviano BRL = "BRL" // Brazil Real BSD = "BSD" // Bahamas Dollar BTN = "BTN" // Bhutan Ngultrum BWP = "BWP" // Botswana Pula BYN = "BYN" // Belarus Ruble BZD = "BZD" // Belize Dollar CAD = "CAD" // Canada Dollar CDF = "CDF" // Congo/Kinshasa Franc CHF = "CHF" // Switzerland Franc CLP = "CLP" // Chile Peso CNY = "CNY" // China Yuan Renminbi COP = "COP" // Colombia Peso CRC = "CRC" // Costa Rica Colon CUC = "CUC" // Cuba Convertible Peso CUP = "CUP" // Cuba Peso CVE = "CVE" // Cape Verde Escudo CZK = "CZK" // Czech Republic Koruna DJF = "DJF" // Djibouti Franc DKK = "DKK" // Denmark Krone DOP = "DOP" // Dominican Republic Peso DZD = "DZD" // Algeria Dinar EGP = "EGP" // Egypt Pound ERN = "ERN" // Eritrea Nakfa ETB = "ETB" // Ethiopia Birr EUR = "EUR" // Euro Member Countries FJD = "FJD" // Fiji Dollar FKP = "FKP" // Falkland Islands (Malvinas) Pound GBP = "GBP" // United Kingdom Pound GEL = "GEL" // Georgia Lari GGP = "GGP" // Guernsey Pound GHS = "GHS" // Ghana Cedi GIP = "GIP" // Gibraltar Pound GMD = "GMD" // Gambia Dalasi GNF = "GNF" // Guinea Franc GTQ = "GTQ" // Guatemala Quetzal GYD = "GYD" // Guyana Dollar HKD = "HKD" // Hong Kong Dollar HNL = "HNL" // Honduras Lempira HRK = "HRK" // Croatia Kuna HTG = "HTG" // Haiti Gourde HUF = "HUF" // Hungary Forint IDR = "IDR" // Indonesia Rupiah ILS = "ILS" // Israel Shekel IMP = "IMP" // Isle of Man Pound INR = "INR" // India Rupee IQD = "IQD" // Iraq Dinar IRR = "IRR" // Iran Rial ISK = "ISK" // Iceland Krona JEP = "JEP" // Jersey Pound JMD = "JMD" // Jamaica Dollar JOD = "JOD" // Jordan Dinar JPY = "JPY" // Japan Yen KES = "KES" // Kenya Shilling KGS = "KGS" // Kyrgyzstan Som KHR = "KHR" // Cambodia Riel KMF = "KMF" // Comoros Franc KPW = "KPW" // Korea (North) Won KRW = "KRW" // Korea (South) Won KWD = "KWD" // Kuwait Dinar KYD = "KYD" // Cayman Islands Dollar KZT = "KZT" // Kazakhstan Tenge LAK = "LAK" // Laos Kip LBP = "LBP" // Lebanon Pound LKR = "LKR" // Sri Lanka Rupee LRD = "LRD" // Liberia Dollar LSL = "LSL" // Lesotho Loti LYD = "LYD" // Libya Dinar MAD = "MAD" // Morocco Dirham MDL = "MDL" // Moldova Leu MGA = "MGA" // Madagascar Ariary MKD = "MKD" // Macedonia Denar MMK = "MMK" // Myanmar (Burma) Kyat MNT = "MNT" // Mongolia Tughrik MOP = "MOP" // Macau Pataca MRO = "MRO" // Mauritania Ouguiya MUR = "MUR" // Mauritius Rupee MVR = "MVR" // Maldives (Maldive Islands) Rufiyaa MWK = "MWK" // Malawi Kwacha MXN = "MXN" // Mexico Peso MYR = "MYR" // Malaysia Ringgit MZN = "MZN" // Mozambique Metical NAD = "NAD" // Namibia Dollar NGN = "NGN" // Nigeria Naira NIO = "NIO" // Nicaragua Cordoba NOK = "NOK" // Norway Krone NPR = "NPR" // Nepal Rupee NZD = "NZD" // New Zealand Dollar OMR = "OMR" // Oman Rial PAB = "PAB" // Panama Balboa PEN = "PEN" // Peru Sol PGK = "PGK" // Papua New Guinea Kina PHP = "PHP" // Philippines Peso PKR = "PKR" // Pakistan Rupee PLN = "PLN" // Poland Zloty PYG = "PYG" // Paraguay Guarani QAR = "QAR" // Qatar Riyal RON = "RON" // Romania New Leu RSD = "RSD" // Serbia Dinar RUB = "RUB" // Russia Ruble RWF = "RWF" // Rwanda Franc SAR = "SAR" // Saudi Arabia Riyal SBD = "SBD" // Solomon Islands Dollar SCR = "SCR" // Seychelles Rupee SDG = "SDG" // Sudan Pound SEK = "SEK" // Sweden Krona SGD = "SGD" // Singapore Dollar SHP = "SHP" // Saint Helena Pound SLL = "SLL" // Sierra Leone Leone SOS = "SOS" // Somalia Shilling SPL = "SPL" // Seborga Luigino SRD = "SRD" // Suriname Dollar STD = "STD" // São Tomé and Príncipe Dobra SVC = "SVC" // El Salvador Colon SYP = "SYP" // Syria Pound SZL = "SZL" // Swaziland Lilangeni THB = "THB" // Thailand Baht TJS = "TJS" // Tajikistan Somoni TMT = "TMT" // Turkmenistan Manat TND = "TND" // Tunisia Dinar TOP = "TOP" // Tonga Pa'anga TRY = "TRY" // Turkey Lira TTD = "TTD" // Trinidad and Tobago Dollar TVD = "TVD" // Tuvalu Dollar TWD = "TWD" // Taiwan New Dollar TZS = "TZS" // Tanzania Shilling UAH = "UAH" // Ukraine Hryvnia UGX = "UGX" // Uganda Shilling USD = "USD" // United States Dollar UYU = "UYU" // Uruguay Peso UZS = "UZS" // Uzbekistan Som VEF = "VEF" // Venezuela Bolivar VND = "VND" // Viet Nam Dong VUV = "VUV" // Vanuatu Vatu WST = "WST" // Samoa Tala XAF = "XAF" // Communauté Financière Africaine (BEAC) CFA Franc BEAC XCD = "XCD" // East Caribbean Dollar XDR = "XDR" // International Monetary Fund (IMF) Special Drawing Rights XOF = "XOF" // Communauté Financière Africaine (BCEAO) Franc XPF = "XPF" // Comptoirs Français du Pacifique (CFP) Franc YER = "YER" // Yemen Rial ZAR = "ZAR" // South Africa Rand ZMW = "ZMW" // Zambia Kwacha ZWD = "ZWD" // Zimbabwe Dollar BTC = "BTC" // Bitcoin )
const CurrencyNull = ""
CurrencyNull represents the SQL NULL for Currency and NullableCurrency. Currency(CurrencyNull).Valid() == false NullableCurrency(CurrencyNull).Valid() == true
Variables ¶
var AmountFinder amountFinder
Functions ¶
func StringIsAmount ¶
StringIsAmount returns if str can be parsed as Amount.
func StringIsCurrency ¶
StringIsCurrency returns if a string can be parsed as Currency.
Types ¶
type Amount ¶
type Amount float64
Amount adds money related methods to float64
func AmountFromPtr ¶
AmountFromPtr dereferences ptr or returns defaultVal if it is nil
func ParseAmount ¶
ParseAmount parses an amount from str accepting only certain decimal digit counts. If no acceptedDecimals are passed, then any decimal digit count is accepted. Infinity and NaN are parsed and returned without error. The Amount.Valid method can be aused to check for infinity and NaN.
func (Amount) Abs ¶
Abs returns the absolute value of a.
Special cases are:
Abs(±Inf) = +Inf Abs(NaN) = NaN
func (Amount) AbsFloat ¶
AbsFloat returns the absolute value of a as float64.
Special cases are:
AbsFloat(±Inf) = +Inf AbsFloat(NaN) = NaN
func (Amount) Copysign ¶
Copysign returns an Amount with the magnitude of a and with the sign of the sign argument.
func (Amount) DividedByRate ¶
DividedByRate returns the amount divided by a rate.
func (*Amount) Equal ¶
Equal returns if two Amount pointers point to Amounts with equal values or equal addresses.
func (*Amount) FloatOr ¶
FloatOr returns the pointed to amount as float64 or defaultVal if ptr is nil.
func (Amount) Format ¶
Format formats the Amount similar to strconv.FormatFloat with the 'f' format option, but with decimalSep as decimal separator instead of a point and optional grouping of the integer part. Valid values for decimalSep are '.' and ','. If thousandsSep is not zero, then the integer part of the number is grouped with thousandsSep between every group of 3 digits. Valid values for thousandsSep are [0, ',', '.'] and thousandsSep must be different from decimalSep. The precision argument controls the number of digits (excluding the exponent). Note that the last digit is not rounded! The special precision -1 uses the smallest number of digits necessary such that ParseFloat will return f exactly.
func (Amount) GoString ¶
GoString returns the amount as string in full float64 precision for debugging
func (Amount) MultipliedByRate ¶
MultipliedByRate returns the amount multiplied by a rate.
func (Amount) Percentage ¶
Percentage returns the amount multiplied by (percent / 100).
func (Amount) RoundToCents ¶
RoundToCents returns the amount rounded to cents (2 decimal places)
func (Amount) RoundToDecimals ¶
RoundToDecimals returns the amount rounded to the passed number of decimal places.
func (Amount) RoundToInt ¶
RoundToInt returns the amount rounded to an integer number
func (*Amount) ScanString ¶
ScanString tries to parse and assign the passed source string as value of the implementing type.
If validate is true, then the Amount.Valid method is checked to return an error if the floating point value is infinite or NaN.
func (Amount) SplitEqually ¶
SplitEqually divides the amount equally into count amounts that are rounded to cents and sum up to the initial amount rounded to cents. The last amount may slightly differ from the others amounts to guarantee that the sum of the rounded cents equals the rounded cents of the initial amount.
func (Amount) SplitProportionally ¶
SplitProportionally splits an amount proportianly to the passed weights into the same number of amounts that get round to cents and makes sure that the sum is identical to the amount rounded to cents. The passed weights can be positive, negative, or zero, so the result amounts can also be positive, negative, or zero.
func (Amount) String ¶
String returns the amount rounded to two decimal places formatted with a dot as decimal separator. String implements the fmt.Stringer interface.
func (*Amount) UnmarshalJSON ¶
UnmarshalJSON implements encoding/json.Unmarshaler and accepts numbers, strings, and null. JSON null and "" will set the amout to zero.
func (Amount) ValidAndGreaterZero ¶
ValidAndGreaterZero returns if the amount is neither infinite nor NaN and greater than zero.
func (Amount) ValidAndHasSign ¶
ValidAndHasSign returns if a.Valid() and if it has the same sign than the passed int argument or any sign if 0 is passed.
func (Amount) ValidAndPositive ¶
ValidAndPositive returns if the amount is neither infinite nor NaN and greater than or equal zero.
func (Amount) ValidAndSmallerZero ¶
ValidAndSmallerZero returns if the amount is neither infinite nor NaN and smaller than zero.
func (Amount) WithNegSign ¶
WithNegSign returns the amount with a negative sign if true is passed, or with a positive sign (abs) if false is passed.
func (Amount) WithPosSign ¶
WithPosSign returns the amount with a positive sign (abs) if true is passed, or with a negative sign if false is passed.
type AmountParser ¶
type AmountParser struct {
// contains filtered or unexported fields
}
AmountParser implements the strfmt.Parser interface for money amounts.
func NewAmountParser ¶
func NewAmountParser(acceptedDecimals ...int) *AmountParser
type Currency ¶
type Currency string
Currency is holds a 3 character ISO 4217 alphabetic code. Currency implements the database/sql.Scanner and database/sql/driver.Valuer interfaces, and will treat an empty Currency string as SQL NULL value. The main difference between Currency and NullableCurrency is: Currency("").Valid() == false NullableCurrency("").Valid() == true
func NormalizeCurrency ¶
NormalizeCurrency returns str as normalized Currency or an error.
func (Currency) EnglishName ¶
EnglishName returns the english name of the currency
func (*Currency) GetOrDefault ¶
GetOrDefault returns the value c references if it is valid and c is not nil. Safe to call on a nil pointer.
func (Currency) Normalized ¶
Normalized normalizes a currency string
func (Currency) NormalizedOrNull ¶
func (c Currency) NormalizedOrNull() NullableCurrency
NormalizedOrNull returns the normalized currency or CurrencyNull if it was not a valid currency.
func (Currency) NullableCurrency ¶
func (c Currency) NullableCurrency() NullableCurrency
NullableCurrency returns c as NullableCurrency where NullableCurrency("").Valid() == true
func (*Currency) ScanString ¶
ScanString tries to parse and assign the passed source string as value of the implementing type.
If validate is true, the source string is checked for validity before it is assigned to the type.
If validate is false and the source string can still be assigned in some non-normalized way it will be assigned without returning an error.
func (Currency) String ¶
String returns the normalized currency as string if possible, else it will be returned unchanged as string. String implements the fmt.Stringer interface.
func (Currency) Symbol ¶
Symbol returns the currency symbol like € for EUR if available, or currency code if no widely recognized symbol is available.
func (*Currency) ValidPtr ¶
ValidPtr returns if c is not nil and can be normalized to a valid currency. Safe to call on a nil pointer.
type CurrencyAmount ¶
func NewCurrencyAmount ¶
func NewCurrencyAmount(currency Currency, amount Amount) CurrencyAmount
func ParseCurrencyAmount ¶
func ParseCurrencyAmount(str string, acceptedDecimals ...int) (result CurrencyAmount, err error)
ParseCurrencyAmount parses a currency and an amount from str with acceptedDecimals. If acceptedDecimals is empty, then any decimal number is accepted.
func (CurrencyAmount) Format ¶
func (ca CurrencyAmount) Format(currencyFirst bool, thousandsSep, decimalSep rune, precision int) string
func (CurrencyAmount) GoString ¶
func (ca CurrencyAmount) GoString() string
func (*CurrencyAmount) Scan ¶
func (ca *CurrencyAmount) Scan(value any) (err error)
Scan implements the database/sql.Scanner interface using ParseCurrencyAmount.
func (*CurrencyAmount) ScanString ¶
func (ca *CurrencyAmount) ScanString(source string, validate bool) error
ScanString tries to parse and assign the passed source string as value of the implementing type.
If validate is true, then the Amount.Valid method is checked to return an error if the floating point value is infinite or NaN.
func (CurrencyAmount) String ¶
func (ca CurrencyAmount) String() string
String implements the fmt.Stringer interface.
type CurrencyAmountParser ¶
type CurrencyAmountParser struct {
// contains filtered or unexported fields
}
CurrencyAmountParser implements the strfmt.Parser interface for money amounts.
func NewCurrencyAmountParser ¶
func NewCurrencyAmountParser(acceptedDecimals ...int) *CurrencyAmountParser
type CurrencyParser ¶
type CurrencyParser struct{}
CurrencyParser implements the strfmt.Parser interface for dates.
type NullableCurrency ¶
type NullableCurrency string
NullableCurrency holds a 3 character ISO 4217 alphabetic code, or an empty string as valid value representing NULL in SQL databases. NullableCurrency implements the database/sql.Scanner and database/sql/driver.Valuer interfaces, and will treat an empty NullableCurrency string as SQL NULL value. The main difference between Currency and NullableCurrency is: Currency("").Valid() == false NullableCurrency("").Valid() == true
func (NullableCurrency) Currency ¶
func (n NullableCurrency) Currency() Currency
func (NullableCurrency) EnglishName ¶
func (n NullableCurrency) EnglishName() string
EnglishName returns the english name of the currency
func (NullableCurrency) Get ¶
func (n NullableCurrency) Get() Currency
Get returns the non nullable Currency value or panics if the NullableCurrency is null. Note: check with IsNull before using Get!
func (NullableCurrency) GetOr ¶
func (n NullableCurrency) GetOr(defaultVal Currency) Currency
GetOr returns the Currency if n valid and not null, or else the passed defaultVal is returned.
func (NullableCurrency) IsNotNull ¶
func (n NullableCurrency) IsNotNull() bool
IsNotNull returns true if the NullableCurrency is not null.
func (NullableCurrency) IsNull ¶
func (n NullableCurrency) IsNull() bool
IsNull returns true if the NullableCurrency is null. IsNull implements the nullable.Nullable interface.
func (NullableCurrency) MarshalJSON ¶
func (n NullableCurrency) MarshalJSON() ([]byte, error)
MarshalJSON implements encoding/json.Marshaler by returning the JSON null value for an empty (null) string.
func (NullableCurrency) Normalized ¶
func (n NullableCurrency) Normalized() (NullableCurrency, error)
Normalized normalizes a currency string
func (NullableCurrency) NormalizedOrNull ¶
func (n NullableCurrency) NormalizedOrNull() NullableCurrency
NormalizedOrNull returns a normalized currency or CurrencyNull if there was an error while normalizing.
func (*NullableCurrency) Scan ¶
func (n *NullableCurrency) Scan(value any) error
Scan implements the database/sql.Scanner interface.
func (*NullableCurrency) ScanString ¶
func (n *NullableCurrency) ScanString(source string, validate bool) error
ScanString tries to parse and assign the passed source string as value of the implementing type.
If validate is true, the source string is checked for validity before it is assigned to the type.
If validate is false and the source string can still be assigned in some non-normalized way it will be assigned without returning an error.
func (*NullableCurrency) Set ¶
func (n *NullableCurrency) Set(currency Currency)
Set sets an ID for this NullableCurrency
func (*NullableCurrency) SetNull ¶
func (n *NullableCurrency) SetNull()
SetNull sets the NullableCurrency to null
func (NullableCurrency) String ¶
func (n NullableCurrency) String() string
String returns the normalized currency as string if possible, else it will be returned unchanged as string. String implements the fmt.Stringer interface.
func (NullableCurrency) StringOr ¶
func (n NullableCurrency) StringOr(defaultString string) string
StringOr returns the NullableCurrency as string or the passed defaultString if the NullableCurrency is null.
func (NullableCurrency) Symbol ¶
func (n NullableCurrency) Symbol() string
Symbol returns the currency symbol like € for EUR if available, or currency code if no widely recognized symbol is available.
func (NullableCurrency) Valid ¶
func (n NullableCurrency) Valid() bool
Valid returns true if n is an empty string, or can be normalized to a valid currency.
func (NullableCurrency) ValidAndNotNull ¶
func (n NullableCurrency) ValidAndNotNull() bool
ValidAndNotNull returns if the currency is valid and not Null.
func (*NullableCurrency) ValidPtr ¶
func (n *NullableCurrency) ValidPtr() bool
Valid returns true if c is nil, an empty string, or a valid 3 character ISO 4217 alphabetic code. Safe to call on a nil pointer.
func (NullableCurrency) Validate ¶
func (n NullableCurrency) Validate() error
Validate returns an error if n is not an empty string and can not be normalized to a valid currency.
type Rate ¶
type Rate float64
Rate is a float64 underneath with additional methods useful for money conversion rates and percentages.
func ParseRate ¶
ParseRate parses a rate from str accepting only certain decimal digit counts. If no acceptedDecimals are passed, then any decimal digit count is accepted. If a string ends with '%' then the parsed number part will be divided by 100.
func RateFromPtr ¶
RateFromPtr dereferences ptr or returns defaultVal if it is nil
func (Rate) Abs ¶
Abs returns the absolute value of r.
Special cases are:
Abs(±Inf) = +Inf Abs(NaN) = NaN
func (Rate) AbsFloat ¶
AbsFloat returns the absolute value of r as float64.
Special cases are:
AbsFloat(±Inf) = +Inf AbsFloat(NaN) = NaN
func (Rate) Copysign ¶
Copysign returns an Rate with the magnitude of a and with the sign of the sign argument.
func (Rate) Format ¶
Format formats the Rate similar to strconv.FormatFloat with the 'f' format option, but with decimalSep as decimal separator instead of a point and optional grouping of the integer part. Valid values for decimalSep are '.' and ','. If thousandsSep is not zero, then the integer part of the number is grouped with thousandsSep between every group of 3 digits. Valid values for thousandsSep are [0, ',', '.'] and thousandsSep must be different from decimalSep. The precision argument controls the number of digits (excluding the exponent). Note that the last digit is not rounded! The special precision -1 uses the smallest number of digits necessary such that ParseFloat will return f exactly.
func (Rate) RoundToDecimals ¶
RoundToDecimals returns the value rounded to the passed number of decimal places.
func (Rate) RoundToInt ¶
RoundToInt returns the value rounded to an integer number
func (*Rate) ScanString ¶
ScanString tries to parse and assign the passed source string as value of the implementing type.
If validate is true, the source string is checked for validity before it is assigned to the type.
If validate is false and the source string can still be assigned in some non-normalized way it will be assigned without returning an error.
func (*Rate) StringOr ¶
StringOr returns strconv.FormatFloat the pointed to rate or defaultVal if ptr is nil.
func (*Rate) UnmarshalJSON ¶
UnmarshalJSON implements encoding/json.Unmarshaler and accepts numbers, strings, and null. JSON null or "" will set the rate to zero. If a string ends with '%' then the parsed number part will be divided by 100.
func (Rate) ValidAndGreaterZero ¶
func (Rate) ValidAndHasSign ¶
ValidAndHasSign returns if r.Valid() and if it has the same sign than the passed int argument or any sign if 0 is passed.
func (Rate) ValidAndPositive ¶
func (Rate) ValidAndSmallerZero ¶
func (Rate) WithNegSign ¶
WithNegSign returns the value with a negative sign if true is passed, or with a positive sign (abs) if false is passed.
func (Rate) WithPosSign ¶
WithPosSign returns the value with a positive sign (abs) if true is passed, or with a negative sign if false is passed.