diff options
author | joeybloggs <Dean.Karn@gmail.com> | 2016-08-16 04:59:49 +0300 |
---|---|---|
committer | joeybloggs <Dean.Karn@gmail.com> | 2016-08-16 04:59:49 +0300 |
commit | aaa28727a7fc0cc7add5d60b31abfe62b983bedd (patch) | |
tree | 032798ba24e7ab36f7532d5ae66df80805029538 /mzn_IR | |
parent | 5e30685010ab9c6da8cc729a3e7eab0b1ae964ae (diff) |
add accounting currency formatting logic + function
Diffstat (limited to 'mzn_IR')
-rw-r--r-- | mzn_IR/mzn_IR.go | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/mzn_IR/mzn_IR.go b/mzn_IR/mzn_IR.go index 76bbabe8..1da98f1f 100644 --- a/mzn_IR/mzn_IR.go +++ b/mzn_IR/mzn_IR.go @@ -96,5 +96,15 @@ func (mzn *mzn_IR) FmtCurrency(num float64, v uint64, currency currency.Type) [] s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) symbol := mzn.currencies[currency] - return []byte(s) + return append(append([]byte{}, symbol...), s...) +} + +// FmtAccounting returns the currency representation of 'num' with digits/precision of 'v' for 'mzn_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 (mzn *mzn_IR) FmtAccounting(num float64, v uint64, currency currency.Type) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + symbol := mzn.currencies[currency] + return append(append([]byte{}, symbol...), s...) } |