diff options
Diffstat (limited to 'ckb_IR/ckb_IR.go')
-rw-r--r-- | ckb_IR/ckb_IR.go | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/ckb_IR/ckb_IR.go b/ckb_IR/ckb_IR.go index 56b22684..690c9959 100644 --- a/ckb_IR/ckb_IR.go +++ b/ckb_IR/ckb_IR.go @@ -103,5 +103,15 @@ func (ckb *ckb_IR) FmtCurrency(num float64, v uint64, currency currency.Type) [] s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) symbol := ckb.currencies[currency] - return []byte(s) + return append(append([]byte{}, symbol...), s...) +} + +// FmtAccounting returns the currency representation of 'num' with digits/precision of 'v' for 'ckb_IR' +// in accounting notation. returned as a []byte just in case the caller wishes to add more and can help +// avoid allocations; otherwise just cast as string. +func (ckb *ckb_IR) FmtAccounting(num float64, v uint64, currency currency.Type) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + symbol := ckb.currencies[currency] + return append(append([]byte{}, symbol...), s...) } |