Documentation ¶
Index ¶
- Variables
- func FormatNumber(value interface{}, precision int, thousand string, decimalStr string) string
- func FormatNumberBigDecimal(x *apd.Decimal, precision int, thousand string, decimalStr string) string
- func FormatNumberBigFloat(x *big.Float, precision int, thousand string, decimal string) string
- func FormatNumberBigRat(x *big.Rat, precision int, thousand string, decimalStr string) string
- func FormatNumberDecimal(x decimal.Decimal, precision int, thousand string, decimalStr string) string
- func FormatNumberFloat64(x float64, precision int, thousand string, decimalStr string) string
- func FormatNumberInt(x int, precision int, thousand string, decimalStr string) string
- func UnformatNumber(n string, precision int, currency string) string
- type Accounting
- func (accounting *Accounting) FormatMoney(value interface{}) string
- func (accounting *Accounting) FormatMoneyBigDecimal(value *apd.Decimal) string
- func (accounting *Accounting) FormatMoneyBigFloat(value *big.Float) string
- func (accounting *Accounting) FormatMoneyBigRat(value *big.Rat) string
- func (accounting *Accounting) FormatMoneyDecimal(value decimal.Decimal) string
- func (accounting *Accounting) FormatMoneyFloat64(value float64) string
- func (accounting *Accounting) FormatMoneyInt(value int) string
- func (accounting *Accounting) SetDecimalSeparator(str string)
- func (accounting *Accounting) SetFormat(str string)
- func (accounting *Accounting) SetFormatNegative(str string)
- func (accounting *Accounting) SetFormatZero(str string)
- func (accounting *Accounting) SetThousandSeparator(str string)
- type Locale
Constants ¶
This section is empty.
Variables ¶
var LocaleInfo map[string]Locale = map[string]Locale{}/* 182 elements not displayed */
Functions ¶
func FormatNumber ¶
FormatNumber is a base function of the library which formats a number with custom precision and separators. FormatNumber supports various types of value by runtime reflection. If you don't need runtime type evaluation, please refer to FormatNumberInt or FormatNumberFloat64. (supported value types : int, int8, int16, int32, int64, uint, uint8, uint16, uint32, uint64, float32, float64, *big.Rat) (also supported value types : decimal.Decimal, *decimal.Decimal *apd.Decimal)
func FormatNumberBigDecimal ¶
func FormatNumberBigDecimal(x *apd.Decimal, precision int, thousand string, decimalStr string) string
FormatNumberBigDecimal only supports *apd.Decimal value. It is faster than FormatNumber, because it does not do any runtime type evaluation.
func FormatNumberBigFloat ¶
FormatNumberBigFloat only supports *big.Float value. It is faster than FormatNumber, because it does not do any runtime type evaluation.
func FormatNumberBigRat ¶
FormatNumberBigRat only supports *big.Rat value. It is faster than FormatNumber, because it does not do any runtime type evaluation.
func FormatNumberDecimal ¶
func FormatNumberDecimal(x decimal.Decimal, precision int, thousand string, decimalStr string) string
FormatNumberDecimal only supports decimal.Decimal value. It is faster than FormatNumber, because it does not do any runtime type evaluation.
func FormatNumberFloat64 ¶
FormatNumberFloat64 only supports float64 value. It is faster than FormatNumber, because it does not do any runtime type evaluation.
func FormatNumberInt ¶
FormatNumberInt only supports int value. It is faster than FormatNumber, because it does not do any runtime type evaluation.
func UnformatNumber ¶
UnformatNumber takes a string of the number to strip currency info on and precision for decimals. It pulls the currency descripter from the LocaleInfo map and uses it to return an unformatted value based on thous sep and decimal sep
Types ¶
type Accounting ¶
type Accounting struct { Symbol string // currency symbol (required) Precision int // currency precision (decimal places) (optional / default: 0) Thousand string // thousand separator (optional / default: ,) Decimal string // decimal separator (optional / default: .) Format string // simple format string allows control of symbol position (%v = value, %s = symbol) (default: %s%v) FormatNegative string // format string for negative values (optional / default: strings.Replace(strings.Replace(accounting.Format, "-", "", -1), "%v", "-%v", -1)) FormatZero string // format string for zero values (optional / default: Format) // contains filtered or unexported fields }
func DefaultAccounting ¶
func DefaultAccounting(symbol string, precision int) *Accounting
DefaultAccounting returns the Accounting with default settings
func NewAccounting ¶
func NewAccounting(symbol string, precision int, thousand, decimal, format, formatNegative, formatZero string) *Accounting
NewAccounting returns the Accounting with default settings
func (*Accounting) FormatMoney ¶
func (accounting *Accounting) FormatMoney(value interface{}) string
FormatMoney is a function for formatting numbers as money values, with customisable currency symbol, precision (decimal places), and thousand/decimal separators. FormatMoney supports various types of value by runtime reflection. If you don't need runtime type evaluation, please refer to FormatMoneyInt or FormatMoneyFloat64. (supported value types : int, int8, int16, int32, int64, uint, uint8, uint16, uint32, uint64, float32, float64, *big.Rat)
func (*Accounting) FormatMoneyBigDecimal ¶
func (accounting *Accounting) FormatMoneyBigDecimal(value *apd.Decimal) string
FormatMoneyBigDecimal only supports *apd.Decimal value. It is faster than FormatMoney, because it does not do any runtime type evaluation.
func (*Accounting) FormatMoneyBigFloat ¶
func (accounting *Accounting) FormatMoneyBigFloat(value *big.Float) string
FormatMoneyBigFloat only supports *big.Float value. It is faster than FormatMoney, because it does not do any runtime type evaluation.
func (*Accounting) FormatMoneyBigRat ¶
func (accounting *Accounting) FormatMoneyBigRat(value *big.Rat) string
FormatMoneyBigRat only supports *big.Rat value. It is faster than FormatMoney, because it does not do any runtime type evaluation.
func (*Accounting) FormatMoneyDecimal ¶
func (accounting *Accounting) FormatMoneyDecimal(value decimal.Decimal) string
FormatMoneyDecimal only supports decimal.Decimal value. It is faster than FormatMoney, because it does not do any runtime type evaluation.
func (*Accounting) FormatMoneyFloat64 ¶
func (accounting *Accounting) FormatMoneyFloat64(value float64) string
FormatMoneyFloat64 only supports float64 value. It is faster than FormatMoney, because it does not do any runtime type evaluation. (Caution: Please do not use float64 to count money. Floats can have errors when you perform operations on them. Using big.Rat is highly recommended.)
func (*Accounting) FormatMoneyInt ¶
func (accounting *Accounting) FormatMoneyInt(value int) string
FormatMoneyInt only supports int type value. It is faster than FormatMoney, because it does not do any runtime type evaluation.
func (*Accounting) SetDecimalSeparator ¶
func (accounting *Accounting) SetDecimalSeparator(str string)
SetDecimalSeparator sets the separator for the decimal separation
func (*Accounting) SetFormat ¶
func (accounting *Accounting) SetFormat(str string)
SetFormat sets the Format default: %s%v (%s=Symbol;%v=Value)
func (*Accounting) SetFormatNegative ¶
func (accounting *Accounting) SetFormatNegative(str string)
SetFormatNegative sets the Format for negative values default: -%s%v (%s=Symbol;%v=Value)
func (*Accounting) SetFormatZero ¶
func (accounting *Accounting) SetFormatZero(str string)
SetFormatZero sets the Format for zero values default: %s%v (%s=Symbol;%v=Value)
func (*Accounting) SetThousandSeparator ¶
func (accounting *Accounting) SetThousandSeparator(str string)
SetThousandSeparator sets the separator for the thousands separation
type Locale ¶
type Locale struct { Name string // currency name FractionLength int // default decimal length ThouSep string // thousands seperator DecSep string // decimal seperator SpaceSep string // space seperator UTFSymbol string // UTF symbol HTMLSymbol string // HTML symbol ComSymbol string // Common symbol Pre bool // symbol before or after currency }