From fb2acb93602d54a9be9ff735bcabbe17a66cb876 Mon Sep 17 00:00:00 2001 From: joeybloggs Date: Fri, 12 Aug 2016 22:28:58 -0400 Subject: add FmtPercent logic. --- asa_TZ/asa_TZ.go | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'asa_TZ') diff --git a/asa_TZ/asa_TZ.go b/asa_TZ/asa_TZ.go index 70b51044..fc28be29 100644 --- a/asa_TZ/asa_TZ.go +++ b/asa_TZ/asa_TZ.go @@ -79,3 +79,13 @@ func (asa *asa_TZ) FmtNumber(num float64, v uint64) []byte { s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) return []byte(s) } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'asa_TZ' and handles both Whole and Real numbers based on 'v' +// returned as a []byte just in case the caller wishes to add more and can help +// avoid allocations; otherwise just cast as string. +// NOTE: 'num' passed into FmtPercent is assumed to be in percent already +func (asa *asa_TZ) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + return []byte(s) +} -- cgit v1.2.3