diff options
author | joeybloggs <Dean.Karn@gmail.com> | 2016-08-13 05:28:58 +0300 |
---|---|---|
committer | joeybloggs <Dean.Karn@gmail.com> | 2016-08-13 05:28:58 +0300 |
commit | fb2acb93602d54a9be9ff735bcabbe17a66cb876 (patch) | |
tree | d492be134bef8c8cea3187a5bd47c6159ad12740 | |
parent | c934af383da7fcfcc5581f5474c094e703c86ff4 (diff) |
add FmtPercent logic.
718 files changed, 22370 insertions, 50 deletions
@@ -117,3 +117,38 @@ func (af *af) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'af' 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 (af *af) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(af.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, af.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, af.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, af.Percent[0]) + + return b +} diff --git a/af_NA/af_NA.go b/af_NA/af_NA.go index e468bdf5..1df2e21a 100644 --- a/af_NA/af_NA.go +++ b/af_NA/af_NA.go @@ -117,3 +117,38 @@ func (af *af_NA) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'af_NA' 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 (af *af_NA) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(af.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, af.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, af.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, af.Percent[0]) + + return b +} diff --git a/af_ZA/af_ZA.go b/af_ZA/af_ZA.go index 6c13d896..e7a5acdc 100644 --- a/af_ZA/af_ZA.go +++ b/af_ZA/af_ZA.go @@ -117,3 +117,38 @@ func (af *af_ZA) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'af_ZA' 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 (af *af_ZA) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(af.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, af.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, af.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, af.Percent[0]) + + return b +} @@ -112,3 +112,42 @@ func (agq *agq) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'agq' 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 (agq *agq) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(agq.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, agq.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(agq.minus) - 1; j >= 0; j-- { + b = append(b, agq.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + for j := len(agq.percent) - 1; j >= 0; j-- { + b = append(b, agq.percent[j]) + } + + return b +} diff --git a/agq_CM/agq_CM.go b/agq_CM/agq_CM.go index 5e14cda8..0644acac 100644 --- a/agq_CM/agq_CM.go +++ b/agq_CM/agq_CM.go @@ -112,3 +112,42 @@ func (agq *agq_CM) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'agq_CM' 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 (agq *agq_CM) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(agq.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, agq.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(agq.minus) - 1; j >= 0; j-- { + b = append(b, agq.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + for j := len(agq.percent) - 1; j >= 0; j-- { + b = append(b, agq.percent[j]) + } + + return b +} @@ -79,3 +79,13 @@ func (ak *ak) 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 'ak' 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 (ak *ak) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + return []byte(s) +} diff --git a/ak_GH/ak_GH.go b/ak_GH/ak_GH.go index abfdd13d..02963795 100644 --- a/ak_GH/ak_GH.go +++ b/ak_GH/ak_GH.go @@ -79,3 +79,13 @@ func (ak *ak_GH) 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 'ak_GH' 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 (ak *ak_GH) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + return []byte(s) +} @@ -126,3 +126,38 @@ func (am *am) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'am' 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 (am *am) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(am.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, am.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, am.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, am.Percent[0]) + + return b +} diff --git a/am_ET/am_ET.go b/am_ET/am_ET.go index 6e514cef..803fdc46 100644 --- a/am_ET/am_ET.go +++ b/am_ET/am_ET.go @@ -126,3 +126,38 @@ func (am *am_ET) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'am_ET' 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 (am *am_ET) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(am.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, am.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, am.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, am.Percent[0]) + + return b +} @@ -182,3 +182,45 @@ func (ar *ar) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'ar' 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 (ar *ar) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(ar.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + for j := len(ar.decimal) - 1; j >= 0; j-- { + b = append(b, ar.decimal[j]) + } + + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(ar.minus) - 1; j >= 0; j-- { + b = append(b, ar.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + for j := len(ar.percent) - 1; j >= 0; j-- { + b = append(b, ar.percent[j]) + } + + return b +} diff --git a/ar_001/ar_001.go b/ar_001/ar_001.go index 5eacd574..ad902289 100644 --- a/ar_001/ar_001.go +++ b/ar_001/ar_001.go @@ -182,3 +182,45 @@ func (ar *ar_001) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'ar_001' 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 (ar *ar_001) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(ar.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + for j := len(ar.decimal) - 1; j >= 0; j-- { + b = append(b, ar.decimal[j]) + } + + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(ar.minus) - 1; j >= 0; j-- { + b = append(b, ar.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + for j := len(ar.percent) - 1; j >= 0; j-- { + b = append(b, ar.percent[j]) + } + + return b +} diff --git a/ar_AE/ar_AE.go b/ar_AE/ar_AE.go index ae26995d..299eb370 100644 --- a/ar_AE/ar_AE.go +++ b/ar_AE/ar_AE.go @@ -182,3 +182,45 @@ func (ar *ar_AE) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'ar_AE' 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 (ar *ar_AE) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(ar.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + for j := len(ar.decimal) - 1; j >= 0; j-- { + b = append(b, ar.decimal[j]) + } + + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(ar.minus) - 1; j >= 0; j-- { + b = append(b, ar.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + for j := len(ar.percent) - 1; j >= 0; j-- { + b = append(b, ar.percent[j]) + } + + return b +} diff --git a/ar_BH/ar_BH.go b/ar_BH/ar_BH.go index 851d0c99..27d09f22 100644 --- a/ar_BH/ar_BH.go +++ b/ar_BH/ar_BH.go @@ -182,3 +182,45 @@ func (ar *ar_BH) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'ar_BH' 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 (ar *ar_BH) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(ar.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + for j := len(ar.decimal) - 1; j >= 0; j-- { + b = append(b, ar.decimal[j]) + } + + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(ar.minus) - 1; j >= 0; j-- { + b = append(b, ar.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + for j := len(ar.percent) - 1; j >= 0; j-- { + b = append(b, ar.percent[j]) + } + + return b +} diff --git a/ar_DJ/ar_DJ.go b/ar_DJ/ar_DJ.go index 9b362228..e84f438b 100644 --- a/ar_DJ/ar_DJ.go +++ b/ar_DJ/ar_DJ.go @@ -182,3 +182,45 @@ func (ar *ar_DJ) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'ar_DJ' 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 (ar *ar_DJ) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(ar.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + for j := len(ar.decimal) - 1; j >= 0; j-- { + b = append(b, ar.decimal[j]) + } + + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(ar.minus) - 1; j >= 0; j-- { + b = append(b, ar.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + for j := len(ar.percent) - 1; j >= 0; j-- { + b = append(b, ar.percent[j]) + } + + return b +} diff --git a/ar_DZ/ar_DZ.go b/ar_DZ/ar_DZ.go index c1701208..cece33ac 100644 --- a/ar_DZ/ar_DZ.go +++ b/ar_DZ/ar_DZ.go @@ -176,3 +176,42 @@ func (ar *ar_DZ) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'ar_DZ' 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 (ar *ar_DZ) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(ar.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, ar.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(ar.minus) - 1; j >= 0; j-- { + b = append(b, ar.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + for j := len(ar.percent) - 1; j >= 0; j-- { + b = append(b, ar.percent[j]) + } + + return b +} diff --git a/ar_EG/ar_EG.go b/ar_EG/ar_EG.go index bd4992f7..6394c1f8 100644 --- a/ar_EG/ar_EG.go +++ b/ar_EG/ar_EG.go @@ -182,3 +182,45 @@ func (ar *ar_EG) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'ar_EG' 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 (ar *ar_EG) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(ar.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + for j := len(ar.decimal) - 1; j >= 0; j-- { + b = append(b, ar.decimal[j]) + } + + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(ar.minus) - 1; j >= 0; j-- { + b = append(b, ar.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + for j := len(ar.percent) - 1; j >= 0; j-- { + b = append(b, ar.percent[j]) + } + + return b +} diff --git a/ar_EH/ar_EH.go b/ar_EH/ar_EH.go index 0c3d85ef..297ed62d 100644 --- a/ar_EH/ar_EH.go +++ b/ar_EH/ar_EH.go @@ -182,3 +182,45 @@ func (ar *ar_EH) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'ar_EH' 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 (ar *ar_EH) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(ar.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + for j := len(ar.decimal) - 1; j >= 0; j-- { + b = append(b, ar.decimal[j]) + } + + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(ar.minus) - 1; j >= 0; j-- { + b = append(b, ar.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + for j := len(ar.percent) - 1; j >= 0; j-- { + b = append(b, ar.percent[j]) + } + + return b +} diff --git a/ar_ER/ar_ER.go b/ar_ER/ar_ER.go index 4ff335a7..f35139af 100644 --- a/ar_ER/ar_ER.go +++ b/ar_ER/ar_ER.go @@ -182,3 +182,45 @@ func (ar *ar_ER) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'ar_ER' 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 (ar *ar_ER) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(ar.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + for j := len(ar.decimal) - 1; j >= 0; j-- { + b = append(b, ar.decimal[j]) + } + + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(ar.minus) - 1; j >= 0; j-- { + b = append(b, ar.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + for j := len(ar.percent) - 1; j >= 0; j-- { + b = append(b, ar.percent[j]) + } + + return b +} diff --git a/ar_IL/ar_IL.go b/ar_IL/ar_IL.go index 3e1d6ead..8c377467 100644 --- a/ar_IL/ar_IL.go +++ b/ar_IL/ar_IL.go @@ -182,3 +182,45 @@ func (ar *ar_IL) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'ar_IL' 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 (ar *ar_IL) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(ar.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + for j := len(ar.decimal) - 1; j >= 0; j-- { + b = append(b, ar.decimal[j]) + } + + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(ar.minus) - 1; j >= 0; j-- { + b = append(b, ar.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + for j := len(ar.percent) - 1; j >= 0; j-- { + b = append(b, ar.percent[j]) + } + + return b +} diff --git a/ar_IQ/ar_IQ.go b/ar_IQ/ar_IQ.go index e45c0b0e..5e9df503 100644 --- a/ar_IQ/ar_IQ.go +++ b/ar_IQ/ar_IQ.go @@ -182,3 +182,45 @@ func (ar *ar_IQ) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'ar_IQ' 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 (ar *ar_IQ) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(ar.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + for j := len(ar.decimal) - 1; j >= 0; j-- { + b = append(b, ar.decimal[j]) + } + + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(ar.minus) - 1; j >= 0; j-- { + b = append(b, ar.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + for j := len(ar.percent) - 1; j >= 0; j-- { + b = append(b, ar.percent[j]) + } + + return b +} diff --git a/ar_JO/ar_JO.go b/ar_JO/ar_JO.go index 419d17c7..40e8f51a 100644 --- a/ar_JO/ar_JO.go +++ b/ar_JO/ar_JO.go @@ -182,3 +182,45 @@ func (ar *ar_JO) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'ar_JO' 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 (ar *ar_JO) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(ar.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + for j := len(ar.decimal) - 1; j >= 0; j-- { + b = append(b, ar.decimal[j]) + } + + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(ar.minus) - 1; j >= 0; j-- { + b = append(b, ar.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + for j := len(ar.percent) - 1; j >= 0; j-- { + b = append(b, ar.percent[j]) + } + + return b +} diff --git a/ar_KM/ar_KM.go b/ar_KM/ar_KM.go index dba08eba..2262a8de 100644 --- a/ar_KM/ar_KM.go +++ b/ar_KM/ar_KM.go @@ -182,3 +182,45 @@ func (ar *ar_KM) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'ar_KM' 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 (ar *ar_KM) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(ar.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + for j := len(ar.decimal) - 1; j >= 0; j-- { + b = append(b, ar.decimal[j]) + } + + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(ar.minus) - 1; j >= 0; j-- { + b = append(b, ar.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + for j := len(ar.percent) - 1; j >= 0; j-- { + b = append(b, ar.percent[j]) + } + + return b +} diff --git a/ar_KW/ar_KW.go b/ar_KW/ar_KW.go index bbb2df78..61a90493 100644 --- a/ar_KW/ar_KW.go +++ b/ar_KW/ar_KW.go @@ -182,3 +182,45 @@ func (ar *ar_KW) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'ar_KW' 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 (ar *ar_KW) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(ar.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + for j := len(ar.decimal) - 1; j >= 0; j-- { + b = append(b, ar.decimal[j]) + } + + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(ar.minus) - 1; j >= 0; j-- { + b = append(b, ar.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + for j := len(ar.percent) - 1; j >= 0; j-- { + b = append(b, ar.percent[j]) + } + + return b +} diff --git a/ar_LB/ar_LB.go b/ar_LB/ar_LB.go index 81cc8ccc..3b53342e 100644 --- a/ar_LB/ar_LB.go +++ b/ar_LB/ar_LB.go @@ -176,3 +176,42 @@ func (ar *ar_LB) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'ar_LB' 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 (ar *ar_LB) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(ar.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, ar.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(ar.minus) - 1; j >= 0; j-- { + b = append(b, ar.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + for j := len(ar.percent) - 1; j >= 0; j-- { + b = append(b, ar.percent[j]) + } + + return b +} diff --git a/ar_LY/ar_LY.go b/ar_LY/ar_LY.go index 1a4f7653..2a64731b 100644 --- a/ar_LY/ar_LY.go +++ b/ar_LY/ar_LY.go @@ -176,3 +176,42 @@ func (ar *ar_LY) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'ar_LY' 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 (ar *ar_LY) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(ar.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, ar.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(ar.minus) - 1; j >= 0; j-- { + b = append(b, ar.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + for j := len(ar.percent) - 1; j >= 0; j-- { + b = append(b, ar.percent[j]) + } + + return b +} diff --git a/ar_MA/ar_MA.go b/ar_MA/ar_MA.go index 43b53c47..a248e31f 100644 --- a/ar_MA/ar_MA.go +++ b/ar_MA/ar_MA.go @@ -176,3 +176,42 @@ func (ar *ar_MA) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'ar_MA' 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 (ar *ar_MA) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(ar.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, ar.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(ar.minus) - 1; j >= 0; j-- { + b = append(b, ar.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + for j := len(ar.percent) - 1; j >= 0; j-- { + b = append(b, ar.percent[j]) + } + + return b +} diff --git a/ar_MR/ar_MR.go b/ar_MR/ar_MR.go index bfb6274f..4f62d703 100644 --- a/ar_MR/ar_MR.go +++ b/ar_MR/ar_MR.go @@ -176,3 +176,42 @@ func (ar *ar_MR) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'ar_MR' 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 (ar *ar_MR) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(ar.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, ar.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(ar.minus) - 1; j >= 0; j-- { + b = append(b, ar.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + for j := len(ar.percent) - 1; j >= 0; j-- { + b = append(b, ar.percent[j]) + } + + return b +} diff --git a/ar_OM/ar_OM.go b/ar_OM/ar_OM.go index 8446d8d4..2fbc66d1 100644 --- a/ar_OM/ar_OM.go +++ b/ar_OM/ar_OM.go @@ -182,3 +182,45 @@ func (ar *ar_OM) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'ar_OM' 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 (ar *ar_OM) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(ar.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + for j := len(ar.decimal) - 1; j >= 0; j-- { + b = append(b, ar.decimal[j]) + } + + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(ar.minus) - 1; j >= 0; j-- { + b = append(b, ar.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + for j := len(ar.percent) - 1; j >= 0; j-- { + b = append(b, ar.percent[j]) + } + + return b +} diff --git a/ar_PS/ar_PS.go b/ar_PS/ar_PS.go index 97f5dc43..44760a7b 100644 --- a/ar_PS/ar_PS.go +++ b/ar_PS/ar_PS.go @@ -182,3 +182,45 @@ func (ar *ar_PS) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'ar_PS' 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 (ar *ar_PS) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(ar.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + for j := len(ar.decimal) - 1; j >= 0; j-- { + b = append(b, ar.decimal[j]) + } + + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(ar.minus) - 1; j >= 0; j-- { + b = append(b, ar.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + for j := len(ar.percent) - 1; j >= 0; j-- { + b = append(b, ar.percent[j]) + } + + return b +} diff --git a/ar_QA/ar_QA.go b/ar_QA/ar_QA.go index 9e28c1cd..326a5a3c 100644 --- a/ar_QA/ar_QA.go +++ b/ar_QA/ar_QA.go @@ -182,3 +182,45 @@ func (ar *ar_QA) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'ar_QA' 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 (ar *ar_QA) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(ar.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + for j := len(ar.decimal) - 1; j >= 0; j-- { + b = append(b, ar.decimal[j]) + } + + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(ar.minus) - 1; j >= 0; j-- { + b = append(b, ar.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + for j := len(ar.percent) - 1; j >= 0; j-- { + b = append(b, ar.percent[j]) + } + + return b +} diff --git a/ar_SA/ar_SA.go b/ar_SA/ar_SA.go index 83ef8a45..b53a457d 100644 --- a/ar_SA/ar_SA.go +++ b/ar_SA/ar_SA.go @@ -182,3 +182,45 @@ func (ar *ar_SA) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'ar_SA' 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 (ar *ar_SA) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(ar.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + for j := len(ar.decimal) - 1; j >= 0; j-- { + b = append(b, ar.decimal[j]) + } + + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(ar.minus) - 1; j >= 0; j-- { + b = append(b, ar.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + for j := len(ar.percent) - 1; j >= 0; j-- { + b = append(b, ar.percent[j]) + } + + return b +} diff --git a/ar_SD/ar_SD.go b/ar_SD/ar_SD.go index e930acc3..2975a539 100644 --- a/ar_SD/ar_SD.go +++ b/ar_SD/ar_SD.go @@ -182,3 +182,45 @@ func (ar *ar_SD) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'ar_SD' 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 (ar *ar_SD) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(ar.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + for j := len(ar.decimal) - 1; j >= 0; j-- { + b = append(b, ar.decimal[j]) + } + + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(ar.minus) - 1; j >= 0; j-- { + b = append(b, ar.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + for j := len(ar.percent) - 1; j >= 0; j-- { + b = append(b, ar.percent[j]) + } + + return b +} diff --git a/ar_SO/ar_SO.go b/ar_SO/ar_SO.go index 2c9f838c..b76299c5 100644 --- a/ar_SO/ar_SO.go +++ b/ar_SO/ar_SO.go @@ -182,3 +182,45 @@ func (ar *ar_SO) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'ar_SO' 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 (ar *ar_SO) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(ar.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + for j := len(ar.decimal) - 1; j >= 0; j-- { + b = append(b, ar.decimal[j]) + } + + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(ar.minus) - 1; j >= 0; j-- { + b = append(b, ar.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + for j := len(ar.percent) - 1; j >= 0; j-- { + b = append(b, ar.percent[j]) + } + + return b +} diff --git a/ar_SS/ar_SS.go b/ar_SS/ar_SS.go index ee45152f..c1f876a6 100644 --- a/ar_SS/ar_SS.go +++ b/ar_SS/ar_SS.go @@ -182,3 +182,45 @@ func (ar *ar_SS) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'ar_SS' 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 (ar *ar_SS) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(ar.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + for j := len(ar.decimal) - 1; j >= 0; j-- { + b = append(b, ar.decimal[j]) + } + + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(ar.minus) - 1; j >= 0; j-- { + b = append(b, ar.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + for j := len(ar.percent) - 1; j >= 0; j-- { + b = append(b, ar.percent[j]) + } + + return b +} diff --git a/ar_SY/ar_SY.go b/ar_SY/ar_SY.go index 2b3f0844..d774b796 100644 --- a/ar_SY/ar_SY.go +++ b/ar_SY/ar_SY.go @@ -182,3 +182,45 @@ func (ar *ar_SY) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'ar_SY' 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 (ar *ar_SY) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(ar.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + for j := len(ar.decimal) - 1; j >= 0; j-- { + b = append(b, ar.decimal[j]) + } + + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(ar.minus) - 1; j >= 0; j-- { + b = append(b, ar.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + for j := len(ar.percent) - 1; j >= 0; j-- { + b = append(b, ar.percent[j]) + } + + return b +} diff --git a/ar_TD/ar_TD.go b/ar_TD/ar_TD.go index 659ce3b5..4c8b4e8a 100644 --- a/ar_TD/ar_TD.go +++ b/ar_TD/ar_TD.go @@ -182,3 +182,45 @@ func (ar *ar_TD) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'ar_TD' 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 (ar *ar_TD) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(ar.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + for j := len(ar.decimal) - 1; j >= 0; j-- { + b = append(b, ar.decimal[j]) + } + + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(ar.minus) - 1; j >= 0; j-- { + b = append(b, ar.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + for j := len(ar.percent) - 1; j >= 0; j-- { + b = append(b, ar.percent[j]) + } + + return b +} diff --git a/ar_TN/ar_TN.go b/ar_TN/ar_TN.go index 19323bb2..166daf08 100644 --- a/ar_TN/ar_TN.go +++ b/ar_TN/ar_TN.go @@ -176,3 +176,42 @@ func (ar *ar_TN) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'ar_TN' 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 (ar *ar_TN) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(ar.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, ar.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(ar.minus) - 1; j >= 0; j-- { + b = append(b, ar.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + for j := len(ar.percent) - 1; j >= 0; j-- { + b = append(b, ar.percent[j]) + } + + return b +} diff --git a/ar_YE/ar_YE.go b/ar_YE/ar_YE.go index e70e2904..11a77ddf 100644 --- a/ar_YE/ar_YE.go +++ b/ar_YE/ar_YE.go @@ -182,3 +182,45 @@ func (ar *ar_YE) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'ar_YE' 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 (ar *ar_YE) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(ar.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + for j := len(ar.decimal) - 1; j >= 0; j-- { + b = append(b, ar.decimal[j]) + } + + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(ar.minus) - 1; j >= 0; j-- { + b = append(b, ar.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + for j := len(ar.percent) - 1; j >= 0; j-- { + b = append(b, ar.percent[j]) + } + + return b +} @@ -145,3 +145,45 @@ func (as *as) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'as' 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 (as *as) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(as.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + for j := len(as.decimal) - 1; j >= 0; j-- { + b = append(b, as.decimal[j]) + } + + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(as.minus) - 1; j >= 0; j-- { + b = append(b, as.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + for j := len(as.percent) - 1; j >= 0; j-- { + b = append(b, as.percent[j]) + } + + return b +} diff --git a/as_IN/as_IN.go b/as_IN/as_IN.go index 37160bc8..586e2c47 100644 --- a/as_IN/as_IN.go +++ b/as_IN/as_IN.go @@ -145,3 +145,45 @@ func (as *as_IN) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'as_IN' 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 (as *as_IN) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(as.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + for j := len(as.decimal) - 1; j >= 0; j-- { + b = append(b, as.decimal[j]) + } + + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(as.minus) - 1; j >= 0; j-- { + b = append(b, as.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + for j := len(as.percent) - 1; j >= 0; j-- { + b = append(b, as.percent[j]) + } + + return b +} @@ -79,3 +79,13 @@ func (asa *asa) 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' 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) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + return []byte(s) +} 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) +} @@ -123,3 +123,45 @@ func (ast *ast) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'ast' 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 (ast *ast) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(ast.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + for j := len(ast.decimal) - 1; j >= 0; j-- { + b = append(b, ast.decimal[j]) + } + + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(ast.minus) - 1; j >= 0; j-- { + b = append(b, ast.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + for j := len(ast.percent) - 1; j >= 0; j-- { + b = append(b, ast.percent[j]) + } + + return b +} diff --git a/ast_ES/ast_ES.go b/ast_ES/ast_ES.go index 0bf9f582..7f13a465 100644 --- a/ast_ES/ast_ES.go +++ b/ast_ES/ast_ES.go @@ -123,3 +123,45 @@ func (ast *ast_ES) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'ast_ES' 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 (ast *ast_ES) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(ast.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + for j := len(ast.decimal) - 1; j >= 0; j-- { + b = append(b, ast.decimal[j]) + } + + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(ast.minus) - 1; j >= 0; j-- { + b = append(b, ast.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + for j := len(ast.percent) - 1; j >= 0; j-- { + b = append(b, ast.percent[j]) + } + + return b +} @@ -66,9 +66,9 @@ func (az *az) OrdinalPluralRule(num float64, v uint64) locales.PluralRule { n := math.Abs(num) i := int64(n) - iMod1000 := i % 1000 iMod10 := i % 10 iMod100 := i % 100 + iMod1000 := i % 1000 if (iMod10 == 1 || iMod10 == 2 || iMod10 == 5 || iMod10 == 7 || iMod10 == 8) || (iMod100 == 20 || iMod100 == 50 || iMod100 == 70 || iMod100 == 80) { return locales.PluralRuleOne @@ -140,3 +140,38 @@ func (az *az) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'az' 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 (az *az) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(az.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, az.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, az.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, az.Percent[0]) + + return b +} diff --git a/az_Cyrl/az_Cyrl.go b/az_Cyrl/az_Cyrl.go index ee136c0a..e5fff26d 100644 --- a/az_Cyrl/az_Cyrl.go +++ b/az_Cyrl/az_Cyrl.go @@ -140,3 +140,38 @@ func (az *az_Cyrl) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'az_Cyrl' 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 (az *az_Cyrl) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(az.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, az.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, az.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, az.Percent[0]) + + return b +} diff --git a/az_Cyrl_AZ/az_Cyrl_AZ.go b/az_Cyrl_AZ/az_Cyrl_AZ.go index bf8833c1..f013e7bf 100644 --- a/az_Cyrl_AZ/az_Cyrl_AZ.go +++ b/az_Cyrl_AZ/az_Cyrl_AZ.go @@ -66,9 +66,9 @@ func (az *az_Cyrl_AZ) OrdinalPluralRule(num float64, v uint64) locales.PluralRul n := math.Abs(num) i := int64(n) - iMod1000 := i % 1000 iMod10 := i % 10 iMod100 := i % 100 + iMod1000 := i % 1000 if (iMod10 == 1 || iMod10 == 2 || iMod10 == 5 || iMod10 == 7 || iMod10 == 8) || (iMod100 == 20 || iMod100 == 50 || iMod100 == 70 || iMod100 == 80) { return locales.PluralRuleOne @@ -140,3 +140,38 @@ func (az *az_Cyrl_AZ) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'az_Cyrl_AZ' 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 (az *az_Cyrl_AZ) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(az.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, az.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, az.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, az.Percent[0]) + + return b +} diff --git a/az_Latn/az_Latn.go b/az_Latn/az_Latn.go index 933d4e3b..dbc85a8e 100644 --- a/az_Latn/az_Latn.go +++ b/az_Latn/az_Latn.go @@ -140,3 +140,38 @@ func (az *az_Latn) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'az_Latn' 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 (az *az_Latn) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(az.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, az.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, az.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, az.Percent[0]) + + return b +} diff --git a/az_Latn_AZ/az_Latn_AZ.go b/az_Latn_AZ/az_Latn_AZ.go index 975e8eb5..55a82367 100644 --- a/az_Latn_AZ/az_Latn_AZ.go +++ b/az_Latn_AZ/az_Latn_AZ.go @@ -140,3 +140,38 @@ func (az *az_Latn_AZ) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'az_Latn_AZ' 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 (az *az_Latn_AZ) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(az.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, az.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, az.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, az.Percent[0]) + + return b +} @@ -112,3 +112,42 @@ func (bas *bas) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'bas' 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 (bas *bas) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(bas.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, bas.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(bas.minus) - 1; j >= 0; j-- { + b = append(b, bas.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + for j := len(bas.percent) - 1; j >= 0; j-- { + b = append(b, bas.percent[j]) + } + + return b +} diff --git a/bas_CM/bas_CM.go b/bas_CM/bas_CM.go index 5ae562ff..cf506cf3 100644 --- a/bas_CM/bas_CM.go +++ b/bas_CM/bas_CM.go @@ -112,3 +112,42 @@ func (bas *bas_CM) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'bas_CM' 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 (bas *bas_CM) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(bas.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, bas.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(bas.minus) - 1; j >= 0; j-- { + b = append(b, bas.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + for j := len(bas.percent) - 1; j >= 0; j-- { + b = append(b, bas.percent[j]) + } + + return b +} @@ -53,8 +53,8 @@ func (be *be) PluralsOrdinal() []locales.PluralRule { func (be *be) CardinalPluralRule(num float64, v uint64) locales.PluralRule { n := math.Abs(num) - nMod10 := math.Mod(n, 10) nMod100 := math.Mod(n, 100) + nMod10 := math.Mod(n, 10) if nMod10 == 1 && nMod100 != 11 { return locales.PluralRuleOne @@ -71,8 +71,8 @@ func (be *be) CardinalPluralRule(num float64, v uint64) locales.PluralRule { func (be *be) OrdinalPluralRule(num float64, v uint64) locales.PluralRule { n := math.Abs(num) - nMod10 := math.Mod(n, 10) nMod100 := math.Mod(n, 100) + nMod10 := math.Mod(n, 10) if (nMod10 == 2 || nMod10 == 3) && (nMod100 != 12 && nMod100 != 13) { return locales.PluralRuleFew @@ -132,3 +132,38 @@ func (be *be) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'be' 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 (be *be) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(be.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, be.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, be.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, be.Percent[0]) + + return b +} diff --git a/be_BY/be_BY.go b/be_BY/be_BY.go index 9bb09acb..8eea4faa 100644 --- a/be_BY/be_BY.go +++ b/be_BY/be_BY.go @@ -71,8 +71,8 @@ func (be *be_BY) CardinalPluralRule(num float64, v uint64) locales.PluralRule { func (be *be_BY) OrdinalPluralRule(num float64, v uint64) locales.PluralRule { n := math.Abs(num) - nMod10 := math.Mod(n, 10) nMod100 := math.Mod(n, 100) + nMod10 := math.Mod(n, 10) if (nMod10 == 2 || nMod10 == 3) && (nMod100 != 12 && nMod100 != 13) { return locales.PluralRuleFew @@ -132,3 +132,38 @@ func (be *be_BY) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'be_BY' 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 (be *be_BY) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(be.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, be.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, be.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, be.Percent[0]) + + return b +} @@ -79,3 +79,13 @@ func (bem *bem) 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 'bem' 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 (bem *bem) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + return []byte(s) +} diff --git a/bem_ZM/bem_ZM.go b/bem_ZM/bem_ZM.go index d7a8d0dd..9dfa9279 100644 --- a/bem_ZM/bem_ZM.go +++ b/bem_ZM/bem_ZM.go @@ -79,3 +79,13 @@ func (bem *bem_ZM) 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 'bem_ZM' 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 (bem *bem_ZM) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + return []byte(s) +} @@ -79,3 +79,13 @@ func (bez *bez) 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 'bez' 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 (bez *bez) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + return []byte(s) +} diff --git a/bez_TZ/bez_TZ.go b/bez_TZ/bez_TZ.go index b6b38f36..9810973e 100644 --- a/bez_TZ/bez_TZ.go +++ b/bez_TZ/bez_TZ.go @@ -79,3 +79,13 @@ func (bez *bez_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 'bez_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 (bez *bez_TZ) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + return []byte(s) +} @@ -117,3 +117,38 @@ func (bg *bg) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'bg' 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 (bg *bg) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(bg.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, bg.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, bg.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, bg.Percent[0]) + + return b +} diff --git a/bg_BG/bg_BG.go b/bg_BG/bg_BG.go index 17a2dc5f..dc643ecf 100644 --- a/bg_BG/bg_BG.go +++ b/bg_BG/bg_BG.go @@ -117,3 +117,38 @@ func (bg *bg_BG) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'bg_BG' 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 (bg *bg_BG) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(bg.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, bg.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, bg.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, bg.Percent[0]) + + return b +} @@ -72,3 +72,13 @@ func (bm *bm) 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 'bm' 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 (bm *bm) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + return []byte(s) +} diff --git a/bm_ML/bm_ML.go b/bm_ML/bm_ML.go index 62206ecd..114dd97f 100644 --- a/bm_ML/bm_ML.go +++ b/bm_ML/bm_ML.go @@ -72,3 +72,13 @@ func (bm *bm_ML) 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 'bm_ML' 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 (bm *bm_ML) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + return []byte(s) +} @@ -156,3 +156,45 @@ func (bn *bn) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'bn' 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 (bn *bn) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(bn.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + for j := len(bn.decimal) - 1; j >= 0; j-- { + b = append(b, bn.decimal[j]) + } + + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(bn.minus) - 1; j >= 0; j-- { + b = append(b, bn.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + for j := len(bn.percent) - 1; j >= 0; j-- { + b = append(b, bn.percent[j]) + } + + return b +} diff --git a/bn_BD/bn_BD.go b/bn_BD/bn_BD.go index 9bb3b077..45a715d8 100644 --- a/bn_BD/bn_BD.go +++ b/bn_BD/bn_BD.go @@ -156,3 +156,45 @@ func (bn *bn_BD) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'bn_BD' 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 (bn *bn_BD) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(bn.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + for j := len(bn.decimal) - 1; j >= 0; j-- { + b = append(b, bn.decimal[j]) + } + + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(bn.minus) - 1; j >= 0; j-- { + b = append(b, bn.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + for j := len(bn.percent) - 1; j >= 0; j-- { + b = append(b, bn.percent[j]) + } + + return b +} diff --git a/bn_IN/bn_IN.go b/bn_IN/bn_IN.go index 2bff3043..8a7b447d 100644 --- a/bn_IN/bn_IN.go +++ b/bn_IN/bn_IN.go @@ -156,3 +156,45 @@ func (bn *bn_IN) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'bn_IN' 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 (bn *bn_IN) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(bn.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + for j := len(bn.decimal) - 1; j >= 0; j-- { + b = append(b, bn.decimal[j]) + } + + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(bn.minus) - 1; j >= 0; j-- { + b = append(b, bn.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + for j := len(bn.percent) - 1; j >= 0; j-- { + b = append(b, bn.percent[j]) + } + + return b +} @@ -109,3 +109,42 @@ func (bo *bo) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'bo' 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 (bo *bo) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(bo.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, bo.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(bo.minus) - 1; j >= 0; j-- { + b = append(b, bo.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + for j := len(bo.percent) - 1; j >= 0; j-- { + b = append(b, bo.percent[j]) + } + + return b +} diff --git a/bo_CN/bo_CN.go b/bo_CN/bo_CN.go index 2d46d23a..f5b80d4e 100644 --- a/bo_CN/bo_CN.go +++ b/bo_CN/bo_CN.go @@ -109,3 +109,42 @@ func (bo *bo_CN) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'bo_CN' 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 (bo *bo_CN) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(bo.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, bo.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(bo.minus) - 1; j >= 0; j-- { + b = append(b, bo.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + for j := len(bo.percent) - 1; j >= 0; j-- { + b = append(b, bo.percent[j]) + } + + return b +} diff --git a/bo_IN/bo_IN.go b/bo_IN/bo_IN.go index a538938f..fa80e21d 100644 --- a/bo_IN/bo_IN.go +++ b/bo_IN/bo_IN.go @@ -109,3 +109,42 @@ func (bo *bo_IN) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'bo_IN' 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 (bo *bo_IN) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(bo.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, bo.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(bo.minus) - 1; j >= 0; j-- { + b = append(b, bo.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + for j := len(bo.percent) - 1; j >= 0; j-- { + b = append(b, bo.percent[j]) + } + + return b +} @@ -131,3 +131,45 @@ func (br *br) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'br' 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 (br *br) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(br.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + for j := len(br.decimal) - 1; j >= 0; j-- { + b = append(b, br.decimal[j]) + } + + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(br.minus) - 1; j >= 0; j-- { + b = append(b, br.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + for j := len(br.percent) - 1; j >= 0; j-- { + b = append(b, br.percent[j]) + } + + return b +} diff --git a/br_FR/br_FR.go b/br_FR/br_FR.go index a8a3fb47..c4b2121c 100644 --- a/br_FR/br_FR.go +++ b/br_FR/br_FR.go @@ -131,3 +131,45 @@ func (br *br_FR) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'br_FR' 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 (br *br_FR) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(br.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + for j := len(br.decimal) - 1; j >= 0; j-- { + b = append(b, br.decimal[j]) + } + + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(br.minus) - 1; j >= 0; j-- { + b = append(b, br.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + for j := len(br.percent) - 1; j >= 0; j-- { + b = append(b, br.percent[j]) + } + + return b +} @@ -123,3 +123,38 @@ func (brx *brx) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'brx' 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 (brx *brx) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(brx.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, brx.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, brx.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, brx.Percent[0]) + + return b +} diff --git a/brx_IN/brx_IN.go b/brx_IN/brx_IN.go index 4211541f..3ab1131e 100644 --- a/brx_IN/brx_IN.go +++ b/brx_IN/brx_IN.go @@ -123,3 +123,38 @@ func (brx *brx_IN) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'brx_IN' 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 (brx *brx_IN) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(brx.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, brx.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, brx.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, brx.Percent[0]) + + return b +} @@ -55,8 +55,8 @@ func (bs *bs) CardinalPluralRule(num float64, v uint64) locales.PluralRule { n := math.Abs(num) i := int64(n) f := locales.F(n, v) - iMod100 := i % 100 iMod10 := i % 10 + iMod100 := i % 100 fMod10 := f % 10 fMod100 := f % 100 @@ -145,3 +145,38 @@ func (bs *bs) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'bs' 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 (bs *bs) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(bs.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, bs.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, bs.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, bs.Percent[0]) + + return b +} diff --git a/bs_Cyrl/bs_Cyrl.go b/bs_Cyrl/bs_Cyrl.go index 7169423a..3f100b3b 100644 --- a/bs_Cyrl/bs_Cyrl.go +++ b/bs_Cyrl/bs_Cyrl.go @@ -55,10 +55,10 @@ func (bs *bs_Cyrl) CardinalPluralRule(num float64, v uint64) locales.PluralRule n := math.Abs(num) i := int64(n) f := locales.F(n, v) - iMod10 := i % 10 iMod100 := i % 100 - fMod100 := f % 100 + iMod10 := i % 10 fMod10 := f % 10 + fMod100 := f % 100 if (v == 0 && iMod10 == 1 && iMod100 != 11) || (fMod10 == 1 && fMod100 != 11) { return locales.PluralRuleOne @@ -145,3 +145,38 @@ func (bs *bs_Cyrl) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'bs_Cyrl' 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 (bs *bs_Cyrl) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(bs.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, bs.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, bs.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, bs.Percent[0]) + + return b +} diff --git a/bs_Cyrl_BA/bs_Cyrl_BA.go b/bs_Cyrl_BA/bs_Cyrl_BA.go index 1faef28a..5eac1233 100644 --- a/bs_Cyrl_BA/bs_Cyrl_BA.go +++ b/bs_Cyrl_BA/bs_Cyrl_BA.go @@ -145,3 +145,38 @@ func (bs *bs_Cyrl_BA) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'bs_Cyrl_BA' 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 (bs *bs_Cyrl_BA) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(bs.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, bs.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, bs.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, bs.Percent[0]) + + return b +} diff --git a/bs_Latn/bs_Latn.go b/bs_Latn/bs_Latn.go index cde70ada..c1f5385a 100644 --- a/bs_Latn/bs_Latn.go +++ b/bs_Latn/bs_Latn.go @@ -145,3 +145,38 @@ func (bs *bs_Latn) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'bs_Latn' 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 (bs *bs_Latn) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(bs.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, bs.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, bs.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, bs.Percent[0]) + + return b +} diff --git a/bs_Latn_BA/bs_Latn_BA.go b/bs_Latn_BA/bs_Latn_BA.go index e9456fec..cf22b3ef 100644 --- a/bs_Latn_BA/bs_Latn_BA.go +++ b/bs_Latn_BA/bs_Latn_BA.go @@ -145,3 +145,38 @@ func (bs *bs_Latn_BA) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'bs_Latn_BA' 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 (bs *bs_Latn_BA) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(bs.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, bs.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, bs.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, bs.Percent[0]) + + return b +} @@ -126,3 +126,38 @@ func (ca *ca) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'ca' 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 (ca *ca) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(ca.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, ca.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, ca.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, ca.Percent[0]) + + return b +} diff --git a/ca_AD/ca_AD.go b/ca_AD/ca_AD.go index 26614f75..67de48df 100644 --- a/ca_AD/ca_AD.go +++ b/ca_AD/ca_AD.go @@ -126,3 +126,38 @@ func (ca *ca_AD) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'ca_AD' 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 (ca *ca_AD) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(ca.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, ca.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, ca.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, ca.Percent[0]) + + return b +} diff --git a/ca_ES/ca_ES.go b/ca_ES/ca_ES.go index e745913e..b161ba11 100644 --- a/ca_ES/ca_ES.go +++ b/ca_ES/ca_ES.go @@ -126,3 +126,38 @@ func (ca *ca_ES) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'ca_ES' 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 (ca *ca_ES) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(ca.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, ca.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, ca.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, ca.Percent[0]) + + return b +} diff --git a/ca_ES_VALENCIA/ca_ES_VALENCIA.go b/ca_ES_VALENCIA/ca_ES_VALENCIA.go index 14cf5ad6..db57c47c 100644 --- a/ca_ES_VALENCIA/ca_ES_VALENCIA.go +++ b/ca_ES_VALENCIA/ca_ES_VALENCIA.go @@ -126,3 +126,38 @@ func (ca *ca_ES_VALENCIA) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'ca_ES_VALENCIA' 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 (ca *ca_ES_VALENCIA) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(ca.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, ca.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, ca.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, ca.Percent[0]) + + return b +} diff --git a/ca_FR/ca_FR.go b/ca_FR/ca_FR.go index 78f02950..96e08e78 100644 --- a/ca_FR/ca_FR.go +++ b/ca_FR/ca_FR.go @@ -126,3 +126,38 @@ func (ca *ca_FR) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'ca_FR' 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 (ca *ca_FR) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(ca.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, ca.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, ca.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, ca.Percent[0]) + + return b +} diff --git a/ca_IT/ca_IT.go b/ca_IT/ca_IT.go index 53e8ff22..4e646228 100644 --- a/ca_IT/ca_IT.go +++ b/ca_IT/ca_IT.go @@ -126,3 +126,38 @@ func (ca *ca_IT) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'ca_IT' 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 (ca *ca_IT) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(ca.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, ca.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, ca.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, ca.Percent[0]) + + return b +} @@ -114,3 +114,38 @@ func (ce *ce) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'ce' 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 (ce *ce) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(ce.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, ce.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, ce.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, ce.Percent[0]) + + return b +} diff --git a/ce_RU/ce_RU.go b/ce_RU/ce_RU.go index 12425097..171be6db 100644 --- a/ce_RU/ce_RU.go +++ b/ce_RU/ce_RU.go @@ -114,3 +114,38 @@ func (ce *ce_RU) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'ce_RU' 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 (ce *ce_RU) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(ce.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, ce.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, ce.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, ce.Percent[0]) + + return b +} @@ -79,3 +79,13 @@ func (cgg *cgg) 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 'cgg' 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 (cgg *cgg) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + return []byte(s) +} diff --git a/cgg_UG/cgg_UG.go b/cgg_UG/cgg_UG.go index f277f546..3b36dc30 100644 --- a/cgg_UG/cgg_UG.go +++ b/cgg_UG/cgg_UG.go @@ -79,3 +79,13 @@ func (cgg *cgg_UG) 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 'cgg_UG' 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 (cgg *cgg_UG) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + return []byte(s) +} @@ -114,3 +114,38 @@ func (chr *chr) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'chr' 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 (chr *chr) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(chr.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, chr.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, chr.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, chr.Percent[0]) + + return b +} diff --git a/chr_US/chr_US.go b/chr_US/chr_US.go index c51ba44c..0df2c6ae 100644 --- a/chr_US/chr_US.go +++ b/chr_US/chr_US.go @@ -114,3 +114,38 @@ func (chr *chr_US) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'chr_US' 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 (chr *chr_US) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(chr.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, chr.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, chr.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, chr.Percent[0]) + + return b +} @@ -79,3 +79,13 @@ func (ckb *ckb) 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 'ckb' 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 (ckb *ckb) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + return []byte(s) +} diff --git a/ckb_IQ/ckb_IQ.go b/ckb_IQ/ckb_IQ.go index 946d9ef0..eb35eb1e 100644 --- a/ckb_IQ/ckb_IQ.go +++ b/ckb_IQ/ckb_IQ.go @@ -79,3 +79,13 @@ func (ckb *ckb_IQ) 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 'ckb_IQ' 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 (ckb *ckb_IQ) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + return []byte(s) +} diff --git a/ckb_IR/ckb_IR.go b/ckb_IR/ckb_IR.go index e0d25194..a7ac0ac7 100644 --- a/ckb_IR/ckb_IR.go +++ b/ckb_IR/ckb_IR.go @@ -79,3 +79,13 @@ func (ckb *ckb_IR) 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 'ckb_IR' 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 (ckb *ckb_IR) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + return []byte(s) +} diff --git a/cmd/generate_resources.go b/cmd/generate_resources.go index 3ee9157c..a8b08481 100644 --- a/cmd/generate_resources.go +++ b/cmd/generate_resources.go @@ -67,17 +67,23 @@ type translator struct { PerMille string PerMilleLen int Currencies string - // FmtNumberFunc string - FmtNumberExists bool - FmtNumberPrefix string - FmtNumberSuffix string + // FmtNumber vars + FmtNumberExists bool FmtNumberGroupLen int FmtNumberSecondaryGroupLen int FmtNumberMinDecimalLen int + // FmtPercent vars + FmtPercentExists bool + FmtPercentGroupLen int + FmtPercentSecondaryGroupLen int + FmtPercentMinDecimalLen int + FmtPercentLeft bool + // calculation only fields DecimalNumberFormat string + PercentNumberFormat string } func main() { @@ -272,6 +278,13 @@ func postProcess(cldr *cldr.CLDR) { } } + if len(trans.PercentNumberFormat) == 0 { + + if found { + trans.PercentNumberFormat = base.PercentNumberFormat + } + } + ldml := cldr.RawLDML(trans.Locale) currencies := make([][]byte, len(globalCurrencies), len(globalCurrencies)) @@ -306,6 +319,7 @@ func postProcess(cldr *cldr.CLDR) { trans.Currencies = fmt.Sprintf("%#v", currencies) parseDecimalNumberFormat(trans) + parsePercentNumberFormat(trans) // trans.FmtNumberFunc = parseDecimalNumberFormat(trans.DecimalNumberFormat, trans.BaseLocale) } } @@ -393,6 +407,16 @@ func preProcess(cldr *cldr.CLDR) { } } + if len(ldml.Numbers.PercentFormats) > 0 && len(ldml.Numbers.PercentFormats[0].PercentFormatLength) > 0 { + + for _, dfl := range ldml.Numbers.PercentFormats[0].PercentFormatLength { + if len(dfl.Type) == 0 { + trans.PercentNumberFormat = dfl.PercentFormat[0].Pattern[0].Data() + break + } + } + } + // var decimalFormat, currencyFormat, currencyAccountingFormat, percentageFormat string // if len(ldml.Numbers.DecimalFormats) > 0 && len(ldml.Numbers.DecimalFormats[0].DecimalFormatLength) > 0 { @@ -431,6 +455,70 @@ func preProcess(cldr *cldr.CLDR) { } } +func parsePercentNumberFormat(trans *translator) (results string) { + + if len(trans.PercentNumberFormat) == 0 { + return + } + + trans.FmtPercentExists = true + + formats := strings.SplitN(trans.PercentNumberFormat, ";", 2) + + // if len(formats) > 1 { + // trans.FmtNumberHasNegativeFormat = true + // } + + match := groupLenRegex.FindString(formats[0]) + if len(match) > 0 { + trans.FmtPercentGroupLen = len(match) - 2 + } + + match = requiredDecimalRegex.FindString(formats[0]) + if len(match) > 0 { + trans.FmtPercentMinDecimalLen = len(match) - 1 + } + + match = secondaryGroupLenRegex.FindString(formats[0]) + if len(match) > 0 { + trans.FmtPercentSecondaryGroupLen = len(match) - 2 + } + + if formats[0][0] == '%' { + trans.FmtPercentLeft = true + } + // trans.FmtPercentLeft + + // start := 0 + // // prefix := "" + + // // positive prefix + // for start = 0; start < len(formats[0]); start++ { + // if formats[0][start] == '#' || formats[0][start] == '0' { + // break + // } + // } + + // // if start > 0 { + // // prefix = formats[0][:start] + // // } + + // end := 0 + + // // positive prefix + // for end = len(formats[0]) - 1; end >= 0; end-- { + // if formats[0][end] == '#' || formats[0][end] == '0' { + // end++ + // break + // } + // } + + // fmt.Println(start) + // fmt.Println(end) + + return +} + func parseDecimalNumberFormat(trans *translator) (results string) { if len(trans.DecimalNumberFormat) == 0 { diff --git a/cmd/translator.tmpl b/cmd/translator.tmpl index 96a75bea..623adb5d 100644 --- a/cmd/translator.tmpl +++ b/cmd/translator.tmpl @@ -175,4 +175,136 @@ func({{ .BaseLocale }} *{{ .Locale }}) FmtNumber(num float64, v uint64) []byte { {{ end -}} } +// FmtPercent returns 'num' with digits/precision of 'v' for '{{ .Locale }}' 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({{ .BaseLocale }} *{{ .Locale }}) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + {{- if eq .FmtPercentExists true }} + {{- if gt .FmtPercentGroupLen 0 }} + l := len(s) + len({{ .BaseLocale }}.decimal) + len({{ .BaseLocale }}.group) * len(s[:len(s)-int(v)-1]) / {{ .FmtPercentGroupLen }} + count := 0 + inWhole := v == 0 + {{- if gt .FmtPercentSecondaryGroupLen 0}} + inSecondary := false + groupThreshold := {{ .FmtPercentGroupLen }} + {{ end -}} + {{ else }} + l := len(s) + len({{ .BaseLocale }}.decimal) + {{ end }} + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + + {{- if eq .DecimalLen 1 }} + b = append(b, {{ .BaseLocale }}.decimal[0]) + {{- else }} + for j := len({{ .BaseLocale }}.decimal) - 1; j >= 0; j-- { + b = append(b, {{ .BaseLocale }}.decimal[j]) + } + {{ end -}} + {{- if gt .FmtPercentGroupLen 0 }} + inWhole = true + {{ end }} + continue + } + + {{ if gt .FmtPercentGroupLen 0 }} + if inWhole { + + {{- if gt .FmtPercentSecondaryGroupLen 0}} + + if count == groupThreshold { + {{- if eq .GroupLen 1 }} + b = append(b, {{ .BaseLocale }}.group[0]) + {{- else }} + for j := len({{ .BaseLocale }}.group) - 1; j >= 0; j-- { + b = append(b, {{ .BaseLocale }}.group[j]) + } + {{ end }} + count = 1 + + if !inSecondary { + inSecondary = true + groupThreshold = {{ .FmtPercentSecondaryGroupLen }} + } + {{ else }} + if count == {{ .FmtPercentGroupLen }} { + {{- if eq .GroupLen 1 }} + b = append(b, {{ .BaseLocale }}.group[0]) + {{- else }} + for j := len({{ .BaseLocale }}.group) - 1; j >= 0; j-- { + b = append(b, {{ .BaseLocale }}.group[j]) + } + {{ end }} + count = 1 + {{ end -}} + } else { + count++ + } + } + + {{ end }} + + b = append(b, s[i]) + } + + if num < 0 { + {{- if eq .MinusLen 1 }} + b = append(b, {{ .BaseLocale }}.minus[0]) + {{ else }} + for j := len({{ .BaseLocale }}.minus) - 1; j >= 0; j-- { + b = append(b, {{ .BaseLocale }}.minus[j]) + } + {{ end -}} + } + + {{ if eq .FmtPercentLeft true }} + {{- if eq .PercentLen 1 }} + b = append(b, {{ .BaseLocale }}.Percent[0]) + {{ else }} + for j := len({{ .BaseLocale }}.percent) - 1; j >= 0; j-- { + b = append(b, {{ .BaseLocale }}.percent[j]) + } + {{ end }} + {{ end }} + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + {{ if gt .FmtPercentMinDecimalLen 0 }} + if int(v) < {{ .FmtPercentMinDecimalLen }} { + + if v == 0 { + b = append(b, {{ .BaseLocale }}.decimal...) + } + + for i := 0; i < {{ .FmtPercentMinDecimalLen }}-int(v); i++ { + b = append(b, '0') + } + } + {{ end }} + + {{ if eq .FmtPercentLeft false }} + {{- if eq .PercentLen 1 }} + b = append(b, {{ .BaseLocale }}.Percent[0]) + {{ else }} + for j := len({{ .BaseLocale }}.percent) - 1; j >= 0; j-- { + b = append(b, {{ .BaseLocale }}.percent[j]) + } + {{ end }} + {{ end }} + + return b + {{ else }} + return []byte(s) + {{ end -}} +} + {{ end }}
\ No newline at end of file @@ -160,3 +160,45 @@ func (cs *cs) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'cs' 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 (cs *cs) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(cs.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + for j := len(cs.decimal) - 1; j >= 0; j-- { + b = append(b, cs.decimal[j]) + } + + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(cs.minus) - 1; j >= 0; j-- { + b = append(b, cs.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + for j := len(cs.percent) - 1; j >= 0; j-- { + b = append(b, cs.percent[j]) + } + + return b +} diff --git a/cs_CZ/cs_CZ.go b/cs_CZ/cs_CZ.go index 84b4bb7f..95cee901 100644 --- a/cs_CZ/cs_CZ.go +++ b/cs_CZ/cs_CZ.go @@ -160,3 +160,45 @@ func (cs *cs_CZ) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'cs_CZ' 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 (cs *cs_CZ) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(cs.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + for j := len(cs.decimal) - 1; j >= 0; j-- { + b = append(b, cs.decimal[j]) + } + + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(cs.minus) - 1; j >= 0; j-- { + b = append(b, cs.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + for j := len(cs.percent) - 1; j >= 0; j-- { + b = append(b, cs.percent[j]) + } + + return b +} @@ -110,3 +110,38 @@ func (cu *cu) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'cu' 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 (cu *cu) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(cu.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, cu.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, cu.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, cu.Percent[0]) + + return b +} diff --git a/cu_RU/cu_RU.go b/cu_RU/cu_RU.go index 534832dc..d2f87574 100644 --- a/cu_RU/cu_RU.go +++ b/cu_RU/cu_RU.go @@ -110,3 +110,38 @@ func (cu *cu_RU) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'cu_RU' 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 (cu *cu_RU) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(cu.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, cu.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, cu.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, cu.Percent[0]) + + return b +} @@ -190,3 +190,45 @@ func (cy *cy) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'cy' 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 (cy *cy) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(cy.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + for j := len(cy.decimal) - 1; j >= 0; j-- { + b = append(b, cy.decimal[j]) + } + + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(cy.minus) - 1; j >= 0; j-- { + b = append(b, cy.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + for j := len(cy.percent) - 1; j >= 0; j-- { + b = append(b, cy.percent[j]) + } + + return b +} diff --git a/cy_GB/cy_GB.go b/cy_GB/cy_GB.go index b2142ef8..af51cfc0 100644 --- a/cy_GB/cy_GB.go +++ b/cy_GB/cy_GB.go @@ -190,3 +190,45 @@ func (cy *cy_GB) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'cy_GB' 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 (cy *cy_GB) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(cy.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + for j := len(cy.decimal) - 1; j >= 0; j-- { + b = append(b, cy.decimal[j]) + } + + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(cy.minus) - 1; j >= 0; j-- { + b = append(b, cy.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + for j := len(cy.percent) - 1; j >= 0; j-- { + b = append(b, cy.percent[j]) + } + + return b +} @@ -129,3 +129,38 @@ func (da *da) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'da' 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 (da *da) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(da.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, da.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, da.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, da.Percent[0]) + + return b +} diff --git a/da_DK/da_DK.go b/da_DK/da_DK.go index eb195110..800d79e1 100644 --- a/da_DK/da_DK.go +++ b/da_DK/da_DK.go @@ -129,3 +129,38 @@ func (da *da_DK) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'da_DK' 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 (da *da_DK) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(da.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, da.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, da.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, da.Percent[0]) + + return b +} diff --git a/da_GL/da_GL.go b/da_GL/da_GL.go index 1022cd5f..bf35bbb4 100644 --- a/da_GL/da_GL.go +++ b/da_GL/da_GL.go @@ -129,3 +129,38 @@ func (da *da_GL) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'da_GL' 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 (da *da_GL) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(da.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, da.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, da.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, da.Percent[0]) + + return b +} @@ -72,3 +72,13 @@ func (dav *dav) 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 'dav' 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 (dav *dav) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + return []byte(s) +} diff --git a/dav_KE/dav_KE.go b/dav_KE/dav_KE.go index 1ae3e8cd..0275239f 100644 --- a/dav_KE/dav_KE.go +++ b/dav_KE/dav_KE.go @@ -72,3 +72,13 @@ func (dav *dav_KE) 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 'dav_KE' 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 (dav *dav_KE) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + return []byte(s) +} @@ -126,3 +126,38 @@ func (de *de) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'de' 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 (de *de) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(de.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, de.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, de.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, de.Percent[0]) + + return b +} diff --git a/de_AT/de_AT.go b/de_AT/de_AT.go index da824a98..0153cf12 100644 --- a/de_AT/de_AT.go +++ b/de_AT/de_AT.go @@ -129,3 +129,38 @@ func (de *de_AT) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'de_AT' 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 (de *de_AT) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(de.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, de.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, de.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, de.Percent[0]) + + return b +} diff --git a/de_BE/de_BE.go b/de_BE/de_BE.go index e42e806b..baa2ac97 100644 --- a/de_BE/de_BE.go +++ b/de_BE/de_BE.go @@ -126,3 +126,38 @@ func (de *de_BE) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'de_BE' 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 (de *de_BE) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(de.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, de.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, de.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, de.Percent[0]) + + return b +} diff --git a/de_CH/de_CH.go b/de_CH/de_CH.go index 733feb76..73483bfe 100644 --- a/de_CH/de_CH.go +++ b/de_CH/de_CH.go @@ -126,3 +126,38 @@ func (de *de_CH) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'de_CH' 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 (de *de_CH) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(de.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, de.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, de.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, de.Percent[0]) + + return b +} diff --git a/de_DE/de_DE.go b/de_DE/de_DE.go index bea45d8d..2455a1f5 100644 --- a/de_DE/de_DE.go +++ b/de_DE/de_DE.go @@ -126,3 +126,38 @@ func (de *de_DE) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'de_DE' 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 (de *de_DE) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(de.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, de.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, de.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, de.Percent[0]) + + return b +} diff --git a/de_LI/de_LI.go b/de_LI/de_LI.go index 05e3af29..5768fd5d 100644 --- a/de_LI/de_LI.go +++ b/de_LI/de_LI.go @@ -126,3 +126,38 @@ func (de *de_LI) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'de_LI' 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 (de *de_LI) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(de.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, de.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, de.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, de.Percent[0]) + + return b +} diff --git a/de_LU/de_LU.go b/de_LU/de_LU.go index e6427d87..7c213350 100644 --- a/de_LU/de_LU.go +++ b/de_LU/de_LU.go @@ -126,3 +126,38 @@ func (de *de_LU) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'de_LU' 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 (de *de_LU) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(de.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, de.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, de.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, de.Percent[0]) + + return b +} @@ -112,3 +112,42 @@ func (dje *dje) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'dje' 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 (dje *dje) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(dje.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, dje.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(dje.minus) - 1; j >= 0; j-- { + b = append(b, dje.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + for j := len(dje.percent) - 1; j >= 0; j-- { + b = append(b, dje.percent[j]) + } + + return b +} diff --git a/dje_NE/dje_NE.go b/dje_NE/dje_NE.go index 585079dc..aec0e849 100644 --- a/dje_NE/dje_NE.go +++ b/dje_NE/dje_NE.go @@ -112,3 +112,42 @@ func (dje *dje_NE) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'dje_NE' 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 (dje *dje_NE) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(dje.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, dje.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(dje.minus) - 1; j >= 0; j-- { + b = append(b, dje.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + for j := len(dje.percent) - 1; j >= 0; j-- { + b = append(b, dje.percent[j]) + } + + return b +} @@ -122,3 +122,38 @@ func (dsb *dsb) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'dsb' 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 (dsb *dsb) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(dsb.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, dsb.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, dsb.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, dsb.Percent[0]) + + return b +} diff --git a/dsb_DE/dsb_DE.go b/dsb_DE/dsb_DE.go index 87eca207..2e43bdae 100644 --- a/dsb_DE/dsb_DE.go +++ b/dsb_DE/dsb_DE.go @@ -122,3 +122,38 @@ func (dsb *dsb_DE) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'dsb_DE' 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 (dsb *dsb_DE) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(dsb.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, dsb.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, dsb.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, dsb.Percent[0]) + + return b +} @@ -112,3 +112,42 @@ func (dua *dua) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'dua' 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 (dua *dua) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(dua.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, dua.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(dua.minus) - 1; j >= 0; j-- { + b = append(b, dua.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + for j := len(dua.percent) - 1; j >= 0; j-- { + b = append(b, dua.percent[j]) + } + + return b +} diff --git a/dua_CM/dua_CM.go b/dua_CM/dua_CM.go index 1e76ec8a..87d16e3c 100644 --- a/dua_CM/dua_CM.go +++ b/dua_CM/dua_CM.go @@ -112,3 +112,42 @@ func (dua *dua_CM) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'dua_CM' 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 (dua *dua_CM) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(dua.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, dua.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(dua.minus) - 1; j >= 0; j-- { + b = append(b, dua.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + for j := len(dua.percent) - 1; j >= 0; j-- { + b = append(b, dua.percent[j]) + } + + return b +} @@ -112,3 +112,42 @@ func (dyo *dyo) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'dyo' 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 (dyo *dyo) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(dyo.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, dyo.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(dyo.minus) - 1; j >= 0; j-- { + b = append(b, dyo.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + for j := len(dyo.percent) - 1; j >= 0; j-- { + b = append(b, dyo.percent[j]) + } + + return b +} diff --git a/dyo_SN/dyo_SN.go b/dyo_SN/dyo_SN.go index c02759b2..c8ab2df3 100644 --- a/dyo_SN/dyo_SN.go +++ b/dyo_SN/dyo_SN.go @@ -112,3 +112,42 @@ func (dyo *dyo_SN) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'dyo_SN' 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 (dyo *dyo_SN) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(dyo.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, dyo.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(dyo.minus) - 1; j >= 0; j-- { + b = append(b, dyo.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + for j := len(dyo.percent) - 1; j >= 0; j-- { + b = append(b, dyo.percent[j]) + } + + return b +} @@ -116,3 +116,38 @@ func (dz *dz) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'dz' 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 (dz *dz) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(dz.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, dz.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, dz.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, dz.Percent[0]) + + return b +} diff --git a/dz_BT/dz_BT.go b/dz_BT/dz_BT.go index 05016eee..4923cd9e 100644 --- a/dz_BT/dz_BT.go +++ b/dz_BT/dz_BT.go @@ -116,3 +116,38 @@ func (dz *dz_BT) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'dz_BT' 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 (dz *dz_BT) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(dz.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, dz.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, dz.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, dz.Percent[0]) + + return b +} @@ -72,3 +72,13 @@ func (ebu *ebu) 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 'ebu' 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 (ebu *ebu) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + return []byte(s) +} diff --git a/ebu_KE/ebu_KE.go b/ebu_KE/ebu_KE.go index 4ca08f23..3b2dfe73 100644 --- a/ebu_KE/ebu_KE.go +++ b/ebu_KE/ebu_KE.go @@ -72,3 +72,13 @@ func (ebu *ebu_KE) 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 'ebu_KE' 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 (ebu *ebu_KE) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + return []byte(s) +} @@ -79,3 +79,13 @@ func (ee *ee) 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 'ee' 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 (ee *ee) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + return []byte(s) +} diff --git a/ee_GH/ee_GH.go b/ee_GH/ee_GH.go index 09e58e5f..55e78d37 100644 --- a/ee_GH/ee_GH.go +++ b/ee_GH/ee_GH.go @@ -79,3 +79,13 @@ func (ee *ee_GH) 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 'ee_GH' 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 (ee *ee_GH) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + return []byte(s) +} diff --git a/ee_TG/ee_TG.go b/ee_TG/ee_TG.go index 637f1152..55e2f899 100644 --- a/ee_TG/ee_TG.go +++ b/ee_TG/ee_TG.go @@ -79,3 +79,13 @@ func (ee *ee_TG) 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 'ee_TG' 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 (ee *ee_TG) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + return []byte(s) +} @@ -125,3 +125,38 @@ func (el *el) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'el' 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 (el *el) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(el.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, el.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, el.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, el.Percent[0]) + + return b +} diff --git a/el_CY/el_CY.go b/el_CY/el_CY.go index 87420582..2fc054c7 100644 --- a/el_CY/el_CY.go +++ b/el_CY/el_CY.go @@ -125,3 +125,38 @@ func (el *el_CY) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'el_CY' 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 (el *el_CY) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(el.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, el.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, el.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, el.Percent[0]) + + return b +} diff --git a/el_GR/el_GR.go b/el_GR/el_GR.go index 8bd8d46e..1e618d1f 100644 --- a/el_GR/el_GR.go +++ b/el_GR/el_GR.go @@ -125,3 +125,38 @@ func (el *el_GR) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'el_GR' 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 (el *el_GR) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(el.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, el.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, el.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, el.Percent[0]) + + return b +} @@ -128,3 +128,38 @@ func (en *en) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'en' 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 (en *en) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(en.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, en.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, en.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, en.Percent[0]) + + return b +} diff --git a/en_001/en_001.go b/en_001/en_001.go index 0f7077fb..b989d434 100644 --- a/en_001/en_001.go +++ b/en_001/en_001.go @@ -128,3 +128,38 @@ func (en *en_001) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'en_001' 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 (en *en_001) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(en.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, en.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, en.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, en.Percent[0]) + + return b +} diff --git a/en_150/en_150.go b/en_150/en_150.go index 9a9eac46..080b7fd7 100644 --- a/en_150/en_150.go +++ b/en_150/en_150.go @@ -128,3 +128,38 @@ func (en *en_150) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'en_150' 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 (en *en_150) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(en.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, en.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, en.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, en.Percent[0]) + + return b +} diff --git a/en_AG/en_AG.go b/en_AG/en_AG.go index ee3f5761..37e7b13a 100644 --- a/en_AG/en_AG.go +++ b/en_AG/en_AG.go @@ -128,3 +128,38 @@ func (en *en_AG) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'en_AG' 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 (en *en_AG) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(en.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, en.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, en.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, en.Percent[0]) + + return b +} diff --git a/en_AI/en_AI.go b/en_AI/en_AI.go index 71e97a0e..2e260115 100644 --- a/en_AI/en_AI.go +++ b/en_AI/en_AI.go @@ -66,8 +66,8 @@ func (en *en_AI) CardinalPluralRule(num float64, v uint64) locales.PluralRule { func (en *en_AI) OrdinalPluralRule(num float64, v uint64) locales.PluralRule { n := math.Abs(num) - nMod100 := math.Mod(n, 100) nMod10 := math.Mod(n, 10) + nMod100 := math.Mod(n, 100) if nMod10 == 1 && nMod100 != 11 { return locales.PluralRuleOne @@ -128,3 +128,38 @@ func (en *en_AI) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'en_AI' 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 (en *en_AI) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(en.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, en.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, en.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, en.Percent[0]) + + return b +} diff --git a/en_AS/en_AS.go b/en_AS/en_AS.go index 58bbe659..f675fc11 100644 --- a/en_AS/en_AS.go +++ b/en_AS/en_AS.go @@ -128,3 +128,38 @@ func (en *en_AS) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'en_AS' 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 (en *en_AS) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(en.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, en.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, en.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, en.Percent[0]) + + return b +} diff --git a/en_AT/en_AT.go b/en_AT/en_AT.go index 4223add7..a70f803b 100644 --- a/en_AT/en_AT.go +++ b/en_AT/en_AT.go @@ -66,8 +66,8 @@ func (en *en_AT) CardinalPluralRule(num float64, v uint64) locales.PluralRule { func (en *en_AT) OrdinalPluralRule(num float64, v uint64) locales.PluralRule { n := math.Abs(num) - nMod10 := math.Mod(n, 10) nMod100 := math.Mod(n, 100) + nMod10 := math.Mod(n, 10) if nMod10 == 1 && nMod100 != 11 { return locales.PluralRuleOne @@ -128,3 +128,38 @@ func (en *en_AT) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'en_AT' 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 (en *en_AT) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(en.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, en.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, en.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, en.Percent[0]) + + return b +} diff --git a/en_AU/en_AU.go b/en_AU/en_AU.go index 0f57438b..b9531aa6 100644 --- a/en_AU/en_AU.go +++ b/en_AU/en_AU.go @@ -128,3 +128,38 @@ func (en *en_AU) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'en_AU' 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 (en *en_AU) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(en.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, en.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, en.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, en.Percent[0]) + + return b +} diff --git a/en_BB/en_BB.go b/en_BB/en_BB.go index c4c04664..97944389 100644 --- a/en_BB/en_BB.go +++ b/en_BB/en_BB.go @@ -66,8 +66,8 @@ func (en *en_BB) CardinalPluralRule(num float64, v uint64) locales.PluralRule { func (en *en_BB) OrdinalPluralRule(num float64, v uint64) locales.PluralRule { n := math.Abs(num) - nMod100 := math.Mod(n, 100) nMod10 := math.Mod(n, 10) + nMod100 := math.Mod(n, 100) if nMod10 == 1 && nMod100 != 11 { return locales.PluralRuleOne @@ -128,3 +128,38 @@ func (en *en_BB) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'en_BB' 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 (en *en_BB) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(en.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, en.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, en.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, en.Percent[0]) + + return b +} diff --git a/en_BE/en_BE.go b/en_BE/en_BE.go index c8709036..3e4d979e 100644 --- a/en_BE/en_BE.go +++ b/en_BE/en_BE.go @@ -128,3 +128,38 @@ func (en *en_BE) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'en_BE' 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 (en *en_BE) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(en.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, en.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, en.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, en.Percent[0]) + + return b +} diff --git a/en_BI/en_BI.go b/en_BI/en_BI.go index 253a1fe7..1d4a8e36 100644 --- a/en_BI/en_BI.go +++ b/en_BI/en_BI.go @@ -128,3 +128,38 @@ func (en *en_BI) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'en_BI' 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 (en *en_BI) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(en.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, en.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, en.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, en.Percent[0]) + + return b +} diff --git a/en_BM/en_BM.go b/en_BM/en_BM.go index 68909266..dedc32a8 100644 --- a/en_BM/en_BM.go +++ b/en_BM/en_BM.go @@ -66,8 +66,8 @@ func (en *en_BM) CardinalPluralRule(num float64, v uint64) locales.PluralRule { func (en *en_BM) OrdinalPluralRule(num float64, v uint64) locales.PluralRule { n := math.Abs(num) - nMod10 := math.Mod(n, 10) nMod100 := math.Mod(n, 100) + nMod10 := math.Mod(n, 10) if nMod10 == 1 && nMod100 != 11 { return locales.PluralRuleOne @@ -128,3 +128,38 @@ func (en *en_BM) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'en_BM' 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 (en *en_BM) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(en.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, en.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, en.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, en.Percent[0]) + + return b +} diff --git a/en_BS/en_BS.go b/en_BS/en_BS.go index c5d6e61e..5c207c51 100644 --- a/en_BS/en_BS.go +++ b/en_BS/en_BS.go @@ -128,3 +128,38 @@ func (en *en_BS) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'en_BS' 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 (en *en_BS) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(en.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, en.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, en.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, en.Percent[0]) + + return b +} diff --git a/en_BW/en_BW.go b/en_BW/en_BW.go index 0941b08e..11ac2c9d 100644 --- a/en_BW/en_BW.go +++ b/en_BW/en_BW.go @@ -128,3 +128,38 @@ func (en *en_BW) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'en_BW' 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 (en *en_BW) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(en.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, en.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, en.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, en.Percent[0]) + + return b +} diff --git a/en_BZ/en_BZ.go b/en_BZ/en_BZ.go index 43c3a09e..c6ee1efc 100644 --- a/en_BZ/en_BZ.go +++ b/en_BZ/en_BZ.go @@ -128,3 +128,38 @@ func (en *en_BZ) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'en_BZ' 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 (en *en_BZ) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(en.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, en.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, en.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, en.Percent[0]) + + return b +} diff --git a/en_CA/en_CA.go b/en_CA/en_CA.go index 9d653450..40d669d5 100644 --- a/en_CA/en_CA.go +++ b/en_CA/en_CA.go @@ -128,3 +128,38 @@ func (en *en_CA) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'en_CA' 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 (en *en_CA) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(en.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, en.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, en.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, en.Percent[0]) + + return b +} diff --git a/en_CC/en_CC.go b/en_CC/en_CC.go index cc7fe6df..9cfb49ca 100644 --- a/en_CC/en_CC.go +++ b/en_CC/en_CC.go @@ -128,3 +128,38 @@ func (en *en_CC) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'en_CC' 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 (en *en_CC) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(en.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, en.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, en.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, en.Percent[0]) + + return b +} diff --git a/en_CH/en_CH.go b/en_CH/en_CH.go index 4dbe9743..7c5b889e 100644 --- a/en_CH/en_CH.go +++ b/en_CH/en_CH.go @@ -128,3 +128,38 @@ func (en *en_CH) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'en_CH' 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 (en *en_CH) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(en.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, en.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, en.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, en.Percent[0]) + + return b +} diff --git a/en_CK/en_CK.go b/en_CK/en_CK.go index 3d7933b0..7cbbfd70 100644 --- a/en_CK/en_CK.go +++ b/en_CK/en_CK.go @@ -128,3 +128,38 @@ func (en *en_CK) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'en_CK' 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 (en *en_CK) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(en.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, en.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, en.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, en.Percent[0]) + + return b +} diff --git a/en_CM/en_CM.go b/en_CM/en_CM.go index a8f83043..9da44775 100644 --- a/en_CM/en_CM.go +++ b/en_CM/en_CM.go @@ -128,3 +128,38 @@ func (en *en_CM) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'en_CM' 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 (en *en_CM) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(en.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, en.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, en.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, en.Percent[0]) + + return b +} diff --git a/en_CX/en_CX.go b/en_CX/en_CX.go index ba63a4dc..2f38b65b 100644 --- a/en_CX/en_CX.go +++ b/en_CX/en_CX.go @@ -128,3 +128,38 @@ func (en *en_CX) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'en_CX' 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 (en *en_CX) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(en.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, en.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, en.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, en.Percent[0]) + + return b +} diff --git a/en_CY/en_CY.go b/en_CY/en_CY.go index 94a692b7..3dc5510f 100644 --- a/en_CY/en_CY.go +++ b/en_CY/en_CY.go @@ -66,8 +66,8 @@ func (en *en_CY) CardinalPluralRule(num float64, v uint64) locales.PluralRule { func (en *en_CY) OrdinalPluralRule(num float64, v uint64) locales.PluralRule { n := math.Abs(num) - nMod100 := math.Mod(n, 100) nMod10 := math.Mod(n, 10) + nMod100 := math.Mod(n, 100) if nMod10 == 1 && nMod100 != 11 { return locales.PluralRuleOne @@ -128,3 +128,38 @@ func (en *en_CY) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'en_CY' 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 (en *en_CY) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(en.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, en.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, en.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, en.Percent[0]) + + return b +} diff --git a/en_DE/en_DE.go b/en_DE/en_DE.go index f3249a8f..578a44dc 100644 --- a/en_DE/en_DE.go +++ b/en_DE/en_DE.go @@ -66,8 +66,8 @@ func (en *en_DE) CardinalPluralRule(num float64, v uint64) locales.PluralRule { func (en *en_DE) OrdinalPluralRule(num float64, v uint64) locales.PluralRule { n := math.Abs(num) - nMod100 := math.Mod(n, 100) nMod10 := math.Mod(n, 10) + nMod100 := math.Mod(n, 100) if nMod10 == 1 && nMod100 != 11 { return locales.PluralRuleOne @@ -128,3 +128,38 @@ func (en *en_DE) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'en_DE' 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 (en *en_DE) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(en.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, en.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, en.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, en.Percent[0]) + + return b +} diff --git a/en_DG/en_DG.go b/en_DG/en_DG.go index eee57d47..ad890469 100644 --- a/en_DG/en_DG.go +++ b/en_DG/en_DG.go @@ -128,3 +128,38 @@ func (en *en_DG) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'en_DG' 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 (en *en_DG) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(en.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, en.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, en.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, en.Percent[0]) + + return b +} diff --git a/en_DK/en_DK.go b/en_DK/en_DK.go index 9084f9a3..49821a5d 100644 --- a/en_DK/en_DK.go +++ b/en_DK/en_DK.go @@ -128,3 +128,38 @@ func (en *en_DK) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'en_DK' 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 (en *en_DK) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(en.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, en.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, en.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, en.Percent[0]) + + return b +} diff --git a/en_DM/en_DM.go b/en_DM/en_DM.go index 57e01cd0..910a7e9d 100644 --- a/en_DM/en_DM.go +++ b/en_DM/en_DM.go @@ -128,3 +128,38 @@ func (en *en_DM) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'en_DM' 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 (en *en_DM) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(en.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, en.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, en.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, en.Percent[0]) + + return b +} diff --git a/en_ER/en_ER.go b/en_ER/en_ER.go index 4bf2350f..03c356e8 100644 --- a/en_ER/en_ER.go +++ b/en_ER/en_ER.go @@ -128,3 +128,38 @@ func (en *en_ER) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'en_ER' 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 (en *en_ER) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(en.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, en.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, en.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, en.Percent[0]) + + return b +} diff --git a/en_FI/en_FI.go b/en_FI/en_FI.go index 319cf957..917f5072 100644 --- a/en_FI/en_FI.go +++ b/en_FI/en_FI.go @@ -131,3 +131,38 @@ func (en *en_FI) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'en_FI' 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 (en *en_FI) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(en.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, en.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, en.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, en.Percent[0]) + + return b +} diff --git a/en_FJ/en_FJ.go b/en_FJ/en_FJ.go index 83fd330b..f2cf6a22 100644 --- a/en_FJ/en_FJ.go +++ b/en_FJ/en_FJ.go @@ -128,3 +128,38 @@ func (en *en_FJ) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'en_FJ' 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 (en *en_FJ) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(en.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, en.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, en.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, en.Percent[0]) + + return b +} diff --git a/en_FK/en_FK.go b/en_FK/en_FK.go index 1ab1e1b6..eb3ebdde 100644 --- a/en_FK/en_FK.go +++ b/en_FK/en_FK.go @@ -128,3 +128,38 @@ func (en *en_FK) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'en_FK' 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 (en *en_FK) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(en.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, en.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, en.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, en.Percent[0]) + + return b +} diff --git a/en_FM/en_FM.go b/en_FM/en_FM.go index ea09b898..45b1573b 100644 --- a/en_FM/en_FM.go +++ b/en_FM/en_FM.go @@ -128,3 +128,38 @@ func (en *en_FM) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'en_FM' 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 (en *en_FM) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(en.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, en.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, en.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, en.Percent[0]) + + return b +} diff --git a/en_GB/en_GB.go b/en_GB/en_GB.go index 60c0a5cd..5feb8b61 100644 --- a/en_GB/en_GB.go +++ b/en_GB/en_GB.go @@ -128,3 +128,38 @@ func (en *en_GB) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'en_GB' 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 (en *en_GB) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(en.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, en.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, en.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, en.Percent[0]) + + return b +} diff --git a/en_GD/en_GD.go b/en_GD/en_GD.go index 011d6227..a6860ad1 100644 --- a/en_GD/en_GD.go +++ b/en_GD/en_GD.go @@ -128,3 +128,38 @@ func (en *en_GD) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'en_GD' 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 (en *en_GD) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(en.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, en.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, en.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, en.Percent[0]) + + return b +} diff --git a/en_GG/en_GG.go b/en_GG/en_GG.go index b8b7d1f2..46c8c111 100644 --- a/en_GG/en_GG.go +++ b/en_GG/en_GG.go @@ -66,8 +66,8 @@ func (en *en_GG) CardinalPluralRule(num float64, v uint64) locales.PluralRule { func (en *en_GG) OrdinalPluralRule(num float64, v uint64) locales.PluralRule { n := math.Abs(num) - nMod100 := math.Mod(n, 100) nMod10 := math.Mod(n, 10) + nMod100 := math.Mod(n, 100) if nMod10 == 1 && nMod100 != 11 { return locales.PluralRuleOne @@ -128,3 +128,38 @@ func (en *en_GG) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'en_GG' 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 (en *en_GG) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(en.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, en.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, en.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, en.Percent[0]) + + return b +} diff --git a/en_GH/en_GH.go b/en_GH/en_GH.go index fc2ff8b6..96e68e5d 100644 --- a/en_GH/en_GH.go +++ b/en_GH/en_GH.go @@ -66,8 +66,8 @@ func (en *en_GH) CardinalPluralRule(num float64, v uint64) locales.PluralRule { func (en *en_GH) OrdinalPluralRule(num float64, v uint64) locales.PluralRule { n := math.Abs(num) - nMod10 := math.Mod(n, 10) nMod100 := math.Mod(n, 100) + nMod10 := math.Mod(n, 10) if nMod10 == 1 && nMod100 != 11 { return locales.PluralRuleOne @@ -128,3 +128,38 @@ func (en *en_GH) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'en_GH' 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 (en *en_GH) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(en.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, en.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, en.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, en.Percent[0]) + + return b +} diff --git a/en_GI/en_GI.go b/en_GI/en_GI.go index 14f666d8..ff26d457 100644 --- a/en_GI/en_GI.go +++ b/en_GI/en_GI.go @@ -128,3 +128,38 @@ func (en *en_GI) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'en_GI' 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 (en *en_GI) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(en.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, en.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, en.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, en.Percent[0]) + + return b +} diff --git a/en_GM/en_GM.go b/en_GM/en_GM.go index 742aeee3..7a66115c 100644 --- a/en_GM/en_GM.go +++ b/en_GM/en_GM.go @@ -128,3 +128,38 @@ func (en *en_GM) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'en_GM' 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 (en *en_GM) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(en.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, en.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, en.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, en.Percent[0]) + + return b +} diff --git a/en_GU/en_GU.go b/en_GU/en_GU.go index 558f5ae1..69528cf8 100644 --- a/en_GU/en_GU.go +++ b/en_GU/en_GU.go @@ -128,3 +128,38 @@ func (en *en_GU) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'en_GU' 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 (en *en_GU) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(en.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, en.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, en.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, en.Percent[0]) + + return b +} diff --git a/en_GY/en_GY.go b/en_GY/en_GY.go index f96cb2f6..ed93a970 100644 --- a/en_GY/en_GY.go +++ b/en_GY/en_GY.go @@ -128,3 +128,38 @@ func (en *en_GY) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'en_GY' 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 (en *en_GY) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(en.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, en.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, en.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, en.Percent[0]) + + return b +} diff --git a/en_HK/en_HK.go b/en_HK/en_HK.go index 6fba1def..759c4817 100644 --- a/en_HK/en_HK.go +++ b/en_HK/en_HK.go @@ -66,8 +66,8 @@ func (en *en_HK) CardinalPluralRule(num float64, v uint64) locales.PluralRule { func (en *en_HK) OrdinalPluralRule(num float64, v uint64) locales.PluralRule { n := math.Abs(num) - nMod100 := math.Mod(n, 100) nMod10 := math.Mod(n, 10) + nMod100 := math.Mod(n, 100) if nMod10 == 1 && nMod100 != 11 { return locales.PluralRuleOne @@ -128,3 +128,38 @@ func (en *en_HK) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'en_HK' 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 (en *en_HK) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(en.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, en.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, en.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, en.Percent[0]) + + return b +} diff --git a/en_IE/en_IE.go b/en_IE/en_IE.go index 53a08d29..98a58f64 100644 --- a/en_IE/en_IE.go +++ b/en_IE/en_IE.go @@ -128,3 +128,38 @@ func (en *en_IE) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'en_IE' 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 (en *en_IE) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(en.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, en.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, en.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, en.Percent[0]) + + return b +} diff --git a/en_IL/en_IL.go b/en_IL/en_IL.go index 7cb23711..93bb4a39 100644 --- a/en_IL/en_IL.go +++ b/en_IL/en_IL.go @@ -128,3 +128,38 @@ func (en *en_IL) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'en_IL' 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 (en *en_IL) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(en.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, en.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, en.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, en.Percent[0]) + + return b +} diff --git a/en_IM/en_IM.go b/en_IM/en_IM.go index 4b0ca810..c18ac043 100644 --- a/en_IM/en_IM.go +++ b/en_IM/en_IM.go @@ -128,3 +128,38 @@ func (en *en_IM) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'en_IM' 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 (en *en_IM) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(en.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, en.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, en.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, en.Percent[0]) + + return b +} diff --git a/en_IN/en_IN.go b/en_IN/en_IN.go index 043854b9..762ea989 100644 --- a/en_IN/en_IN.go +++ b/en_IN/en_IN.go @@ -137,3 +137,38 @@ func (en *en_IN) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'en_IN' 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 (en *en_IN) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(en.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, en.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, en.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, en.Percent[0]) + + return b +} diff --git a/en_IO/en_IO.go b/en_IO/en_IO.go index 14079f07..2375b64f 100644 --- a/en_IO/en_IO.go +++ b/en_IO/en_IO.go @@ -128,3 +128,38 @@ func (en *en_IO) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'en_IO' 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 (en *en_IO) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(en.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, en.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, en.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, en.Percent[0]) + + return b +} diff --git a/en_JE/en_JE.go b/en_JE/en_JE.go index 1022c5af..772eb2d9 100644 --- a/en_JE/en_JE.go +++ b/en_JE/en_JE.go @@ -128,3 +128,38 @@ func (en *en_JE) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'en_JE' 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 (en *en_JE) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(en.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, en.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, en.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, en.Percent[0]) + + return b +} diff --git a/en_JM/en_JM.go b/en_JM/en_JM.go index 744feb51..a218a0db 100644 --- a/en_JM/en_JM.go +++ b/en_JM/en_JM.go @@ -66,8 +66,8 @@ func (en *en_JM) CardinalPluralRule(num float64, v uint64) locales.PluralRule { func (en *en_JM) OrdinalPluralRule(num float64, v uint64) locales.PluralRule { n := math.Abs(num) - nMod10 := math.Mod(n, 10) nMod100 := math.Mod(n, 100) + nMod10 := math.Mod(n, 10) if nMod10 == 1 && nMod100 != 11 { return locales.PluralRuleOne @@ -128,3 +128,38 @@ func (en *en_JM) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'en_JM' 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 (en *en_JM) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(en.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, en.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, en.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, en.Percent[0]) + + return b +} diff --git a/en_KE/en_KE.go b/en_KE/en_KE.go index c20d79bd..50fa3497 100644 --- a/en_KE/en_KE.go +++ b/en_KE/en_KE.go @@ -128,3 +128,38 @@ func (en *en_KE) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'en_KE' 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 (en *en_KE) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(en.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, en.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, en.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, en.Percent[0]) + + return b +} diff --git a/en_KI/en_KI.go b/en_KI/en_KI.go index 4de8b6a6..bbe56cc6 100644 --- a/en_KI/en_KI.go +++ b/en_KI/en_KI.go @@ -128,3 +128,38 @@ func (en *en_KI) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'en_KI' 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 (en *en_KI) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(en.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, en.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, en.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, en.Percent[0]) + + return b +} diff --git a/en_KN/en_KN.go b/en_KN/en_KN.go index 749a570b..585adfd3 100644 --- a/en_KN/en_KN.go +++ b/en_KN/en_KN.go @@ -66,8 +66,8 @@ func (en *en_KN) CardinalPluralRule(num float64, v uint64) locales.PluralRule { func (en *en_KN) OrdinalPluralRule(num float64, v uint64) locales.PluralRule { n := math.Abs(num) - nMod100 := math.Mod(n, 100) nMod10 := math.Mod(n, 10) + nMod100 := math.Mod(n, 100) if nMod10 == 1 && nMod100 != 11 { return locales.PluralRuleOne @@ -128,3 +128,38 @@ func (en *en_KN) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'en_KN' 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 (en *en_KN) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(en.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, en.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, en.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, en.Percent[0]) + + return b +} diff --git a/en_KY/en_KY.go b/en_KY/en_KY.go index 2d2555b4..9a29cf34 100644 --- a/en_KY/en_KY.go +++ b/en_KY/en_KY.go @@ -66,8 +66,8 @@ func (en *en_KY) CardinalPluralRule(num float64, v uint64) locales.PluralRule { func (en *en_KY) OrdinalPluralRule(num float64, v uint64) locales.PluralRule { n := math.Abs(num) - nMod100 := math.Mod(n, 100) nMod10 := math.Mod(n, 10) + nMod100 := math.Mod(n, 100) if nMod10 == 1 && nMod100 != 11 { return locales.PluralRuleOne @@ -128,3 +128,38 @@ func (en *en_KY) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'en_KY' 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 (en *en_KY) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(en.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, en.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, en.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, en.Percent[0]) + + return b +} diff --git a/en_LC/en_LC.go b/en_LC/en_LC.go index b9243bc1..ab636c8e 100644 --- a/en_LC/en_LC.go +++ b/en_LC/en_LC.go @@ -128,3 +128,38 @@ func (en *en_LC) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'en_LC' 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 (en *en_LC) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(en.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, en.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, en.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, en.Percent[0]) + + return b +} diff --git a/en_LR/en_LR.go b/en_LR/en_LR.go index 994aa26c..8bd0cb13 100644 --- a/en_LR/en_LR.go +++ b/en_LR/en_LR.go @@ -128,3 +128,38 @@ func (en *en_LR) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'en_LR' 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 (en *en_LR) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(en.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, en.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, en.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, en.Percent[0]) + + return b +} diff --git a/en_LS/en_LS.go b/en_LS/en_LS.go index a43ad93a..4fafd77b 100644 --- a/en_LS/en_LS.go +++ b/en_LS/en_LS.go @@ -128,3 +128,38 @@ func (en *en_LS) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'en_LS' 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 (en *en_LS) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(en.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, en.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, en.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, en.Percent[0]) + + return b +} diff --git a/en_MG/en_MG.go b/en_MG/en_MG.go index 89be3d4f..e895390c 100644 --- a/en_MG/en_MG.go +++ b/en_MG/en_MG.go @@ -128,3 +128,38 @@ func (en *en_MG) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'en_MG' 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 (en *en_MG) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(en.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, en.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, en.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, en.Percent[0]) + + return b +} diff --git a/en_MH/en_MH.go b/en_MH/en_MH.go index 8c8d44bc..2c5f1a5e 100644 --- a/en_MH/en_MH.go +++ b/en_MH/en_MH.go @@ -128,3 +128,38 @@ func (en *en_MH) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'en_MH' 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 (en *en_MH) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(en.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, en.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, en.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, en.Percent[0]) + + return b +} diff --git a/en_MO/en_MO.go b/en_MO/en_MO.go index 1c72a979..1263e40a 100644 --- a/en_MO/en_MO.go +++ b/en_MO/en_MO.go @@ -128,3 +128,38 @@ func (en *en_MO) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'en_MO' 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 (en *en_MO) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(en.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, en.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, en.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, en.Percent[0]) + + return b +} diff --git a/en_MP/en_MP.go b/en_MP/en_MP.go index 7e733c46..6378cfc2 100644 --- a/en_MP/en_MP.go +++ b/en_MP/en_MP.go @@ -66,8 +66,8 @@ func (en *en_MP) CardinalPluralRule(num float64, v uint64) locales.PluralRule { func (en *en_MP) OrdinalPluralRule(num float64, v uint64) locales.PluralRule { n := math.Abs(num) - nMod100 := math.Mod(n, 100) nMod10 := math.Mod(n, 10) + nMod100 := math.Mod(n, 100) if nMod10 == 1 && nMod100 != 11 { return locales.PluralRuleOne @@ -128,3 +128,38 @@ func (en *en_MP) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'en_MP' 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 (en *en_MP) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(en.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, en.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, en.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, en.Percent[0]) + + return b +} diff --git a/en_MS/en_MS.go b/en_MS/en_MS.go index ec8d7ffa..584a7f0b 100644 --- a/en_MS/en_MS.go +++ b/en_MS/en_MS.go @@ -128,3 +128,38 @@ func (en *en_MS) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'en_MS' 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 (en *en_MS) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(en.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, en.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, en.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, en.Percent[0]) + + return b +} diff --git a/en_MT/en_MT.go b/en_MT/en_MT.go index 2f81347e..9138f965 100644 --- a/en_MT/en_MT.go +++ b/en_MT/en_MT.go @@ -128,3 +128,38 @@ func (en *en_MT) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'en_MT' 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 (en *en_MT) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(en.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, en.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, en.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, en.Percent[0]) + + return b +} diff --git a/en_MU/en_MU.go b/en_MU/en_MU.go index 52e4cc15..3a206f0e 100644 --- a/en_MU/en_MU.go +++ b/en_MU/en_MU.go @@ -128,3 +128,38 @@ func (en *en_MU) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'en_MU' 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 (en *en_MU) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(en.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, en.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, en.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, en.Percent[0]) + + return b +} diff --git a/en_MW/en_MW.go b/en_MW/en_MW.go index 466ac98a..20378e0a 100644 --- a/en_MW/en_MW.go +++ b/en_MW/en_MW.go @@ -128,3 +128,38 @@ func (en *en_MW) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'en_MW' 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 (en *en_MW) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(en.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, en.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, en.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, en.Percent[0]) + + return b +} diff --git a/en_MY/en_MY.go b/en_MY/en_MY.go index efaa5609..e99ea17a 100644 --- a/en_MY/en_MY.go +++ b/en_MY/en_MY.go @@ -128,3 +128,38 @@ func (en *en_MY) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'en_MY' 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 (en *en_MY) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(en.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, en.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, en.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, en.Percent[0]) + + return b +} diff --git a/en_NA/en_NA.go b/en_NA/en_NA.go index d1b57e63..37c4cde0 100644 --- a/en_NA/en_NA.go +++ b/en_NA/en_NA.go @@ -128,3 +128,38 @@ func (en *en_NA) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'en_NA' 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 (en *en_NA) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(en.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, en.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, en.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, en.Percent[0]) + + return b +} diff --git a/en_NF/en_NF.go b/en_NF/en_NF.go index 495f2cd9..a22b6287 100644 --- a/en_NF/en_NF.go +++ b/en_NF/en_NF.go @@ -128,3 +128,38 @@ func (en *en_NF) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'en_NF' 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 (en *en_NF) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(en.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, en.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, en.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, en.Percent[0]) + + return b +} diff --git a/en_NG/en_NG.go b/en_NG/en_NG.go index e616151a..b75f53a8 100644 --- a/en_NG/en_NG.go +++ b/en_NG/en_NG.go @@ -66,8 +66,8 @@ func (en *en_NG) CardinalPluralRule(num float64, v uint64) locales.PluralRule { func (en *en_NG) OrdinalPluralRule(num float64, v uint64) locales.PluralRule { n := math.Abs(num) - nMod10 := math.Mod(n, 10) nMod100 := math.Mod(n, 100) + nMod10 := math.Mod(n, 10) if nMod10 == 1 && nMod100 != 11 { return locales.PluralRuleOne @@ -128,3 +128,38 @@ func (en *en_NG) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'en_NG' 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 (en *en_NG) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(en.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, en.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, en.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, en.Percent[0]) + + return b +} diff --git a/en_NL/en_NL.go b/en_NL/en_NL.go index 84dba0df..c56a101b 100644 --- a/en_NL/en_NL.go +++ b/en_NL/en_NL.go @@ -128,3 +128,38 @@ func (en *en_NL) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'en_NL' 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 (en *en_NL) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(en.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, en.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, en.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, en.Percent[0]) + + return b +} diff --git a/en_NR/en_NR.go b/en_NR/en_NR.go index 25a8847f..700f7b68 100644 --- a/en_NR/en_NR.go +++ b/en_NR/en_NR.go @@ -128,3 +128,38 @@ func (en *en_NR) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'en_NR' 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 (en *en_NR) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(en.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, en.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, en.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, en.Percent[0]) + + return b +} diff --git a/en_NU/en_NU.go b/en_NU/en_NU.go index e185e360..71cc7db9 100644 --- a/en_NU/en_NU.go +++ b/en_NU/en_NU.go @@ -128,3 +128,38 @@ func (en *en_NU) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'en_NU' 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 (en *en_NU) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(en.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, en.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, en.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, en.Percent[0]) + + return b +} diff --git a/en_NZ/en_NZ.go b/en_NZ/en_NZ.go index 29b02990..e257a12a 100644 --- a/en_NZ/en_NZ.go +++ b/en_NZ/en_NZ.go @@ -66,8 +66,8 @@ func (en *en_NZ) CardinalPluralRule(num float64, v uint64) locales.PluralRule { func (en *en_NZ) OrdinalPluralRule(num float64, v uint64) locales.PluralRule { n := math.Abs(num) - nMod100 := math.Mod(n, 100) nMod10 := math.Mod(n, 10) + nMod100 := math.Mod(n, 100) if nMod10 == 1 && nMod100 != 11 { return locales.PluralRuleOne @@ -128,3 +128,38 @@ func (en *en_NZ) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'en_NZ' 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 (en *en_NZ) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(en.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, en.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, en.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, en.Percent[0]) + + return b +} diff --git a/en_PG/en_PG.go b/en_PG/en_PG.go index e336da5a..0a34f3b4 100644 --- a/en_PG/en_PG.go +++ b/en_PG/en_PG.go @@ -128,3 +128,38 @@ func (en *en_PG) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'en_PG' 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 (en *en_PG) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(en.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, en.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, en.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, en.Percent[0]) + + return b +} diff --git a/en_PH/en_PH.go b/en_PH/en_PH.go index d058bffe..e53c43e7 100644 --- a/en_PH/en_PH.go +++ b/en_PH/en_PH.go @@ -128,3 +128,38 @@ func (en *en_PH) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'en_PH' 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 (en *en_PH) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(en.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, en.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, en.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, en.Percent[0]) + + return b +} diff --git a/en_PK/en_PK.go b/en_PK/en_PK.go index 8d99884a..05437377 100644 --- a/en_PK/en_PK.go +++ b/en_PK/en_PK.go @@ -128,3 +128,38 @@ func (en *en_PK) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'en_PK' 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 (en *en_PK) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(en.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, en.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, en.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, en.Percent[0]) + + return b +} diff --git a/en_PN/en_PN.go b/en_PN/en_PN.go index 7a4c694b..e1c26fd8 100644 --- a/en_PN/en_PN.go +++ b/en_PN/en_PN.go @@ -128,3 +128,38 @@ func (en *en_PN) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'en_PN' 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 (en *en_PN) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(en.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, en.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, en.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, en.Percent[0]) + + return b +} diff --git a/en_PR/en_PR.go b/en_PR/en_PR.go index 5d04b043..3b3947df 100644 --- a/en_PR/en_PR.go +++ b/en_PR/en_PR.go @@ -128,3 +128,38 @@ func (en *en_PR) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'en_PR' 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 (en *en_PR) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(en.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, en.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, en.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, en.Percent[0]) + + return b +} diff --git a/en_PW/en_PW.go b/en_PW/en_PW.go index 1c091d1e..e1f3b312 100644 --- a/en_PW/en_PW.go +++ b/en_PW/en_PW.go @@ -128,3 +128,38 @@ func (en *en_PW) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'en_PW' 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 (en *en_PW) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(en.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, en.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, en.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, en.Percent[0]) + + return b +} diff --git a/en_RW/en_RW.go b/en_RW/en_RW.go index 638e2ab9..4d8cba74 100644 --- a/en_RW/en_RW.go +++ b/en_RW/en_RW.go @@ -128,3 +128,38 @@ func (en *en_RW) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'en_RW' 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 (en *en_RW) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(en.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, en.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, en.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, en.Percent[0]) + + return b +} diff --git a/en_SB/en_SB.go b/en_SB/en_SB.go index b66fb3be..09df165a 100644 --- a/en_SB/en_SB.go +++ b/en_SB/en_SB.go @@ -128,3 +128,38 @@ func (en *en_SB) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'en_SB' 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 (en *en_SB) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(en.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, en.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, en.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, en.Percent[0]) + + return b +} diff --git a/en_SC/en_SC.go b/en_SC/en_SC.go index 3a918b05..67fc4095 100644 --- a/en_SC/en_SC.go +++ b/en_SC/en_SC.go @@ -66,8 +66,8 @@ func (en *en_SC) CardinalPluralRule(num float64, v uint64) locales.PluralRule { func (en *en_SC) OrdinalPluralRule(num float64, v uint64) locales.PluralRule { n := math.Abs(num) - nMod100 := math.Mod(n, 100) nMod10 := math.Mod(n, 10) + nMod100 := math.Mod(n, 100) if nMod10 == 1 && nMod100 != 11 { return locales.PluralRuleOne @@ -128,3 +128,38 @@ func (en *en_SC) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'en_SC' 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 (en *en_SC) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(en.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, en.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, en.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, en.Percent[0]) + + return b +} diff --git a/en_SD/en_SD.go b/en_SD/en_SD.go index 6f7c89a6..e26c33b9 100644 --- a/en_SD/en_SD.go +++ b/en_SD/en_SD.go @@ -128,3 +128,38 @@ func (en *en_SD) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'en_SD' 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 (en *en_SD) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(en.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, en.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, en.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, en.Percent[0]) + + return b +} diff --git a/en_SE/en_SE.go b/en_SE/en_SE.go index 3920851f..7cd03355 100644 --- a/en_SE/en_SE.go +++ b/en_SE/en_SE.go @@ -131,3 +131,38 @@ func (en *en_SE) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'en_SE' 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 (en *en_SE) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(en.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, en.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, en.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, en.Percent[0]) + + return b +} diff --git a/en_SG/en_SG.go b/en_SG/en_SG.go index 30f47783..ae803351 100644 --- a/en_SG/en_SG.go +++ b/en_SG/en_SG.go @@ -128,3 +128,38 @@ func (en *en_SG) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'en_SG' 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 (en *en_SG) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(en.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, en.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, en.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, en.Percent[0]) + + return b +} diff --git a/en_SH/en_SH.go b/en_SH/en_SH.go index c9fa5e68..ce0a3e8b 100644 --- a/en_SH/en_SH.go +++ b/en_SH/en_SH.go @@ -128,3 +128,38 @@ func (en *en_SH) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'en_SH' 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 (en *en_SH) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(en.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, en.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, en.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, en.Percent[0]) + + return b +} diff --git a/en_SI/en_SI.go b/en_SI/en_SI.go index aa35ca1f..86ff34c7 100644 --- a/en_SI/en_SI.go +++ b/en_SI/en_SI.go @@ -128,3 +128,38 @@ func (en *en_SI) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'en_SI' 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 (en *en_SI) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(en.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, en.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, en.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, en.Percent[0]) + + return b +} diff --git a/en_SL/en_SL.go b/en_SL/en_SL.go index e4916ca2..844416a7 100644 --- a/en_SL/en_SL.go +++ b/en_SL/en_SL.go @@ -128,3 +128,38 @@ func (en *en_SL) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'en_SL' 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 (en *en_SL) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(en.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, en.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, en.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, en.Percent[0]) + + return b +} diff --git a/en_SS/en_SS.go b/en_SS/en_SS.go index 2d554caa..0ef2035c 100644 --- a/en_SS/en_SS.go +++ b/en_SS/en_SS.go @@ -128,3 +128,38 @@ func (en *en_SS) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'en_SS' 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 (en *en_SS) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(en.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, en.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, en.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, en.Percent[0]) + + return b +} diff --git a/en_SX/en_SX.go b/en_SX/en_SX.go index 0141baaf..b2b1c368 100644 --- a/en_SX/en_SX.go +++ b/en_SX/en_SX.go @@ -66,8 +66,8 @@ func (en *en_SX) CardinalPluralRule(num float64, v uint64) locales.PluralRule { func (en *en_SX) OrdinalPluralRule(num float64, v uint64) locales.PluralRule { n := math.Abs(num) - nMod100 := math.Mod(n, 100) nMod10 := math.Mod(n, 10) + nMod100 := math.Mod(n, 100) if nMod10 == 1 && nMod100 != 11 { return locales.PluralRuleOne @@ -128,3 +128,38 @@ func (en *en_SX) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'en_SX' 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 (en *en_SX) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(en.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, en.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, en.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, en.Percent[0]) + + return b +} diff --git a/en_SZ/en_SZ.go b/en_SZ/en_SZ.go index ccef0ede..c6516224 100644 --- a/en_SZ/en_SZ.go +++ b/en_SZ/en_SZ.go @@ -128,3 +128,38 @@ func (en *en_SZ) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'en_SZ' 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 (en *en_SZ) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(en.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, en.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, en.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, en.Percent[0]) + + return b +} diff --git a/en_TC/en_TC.go b/en_TC/en_TC.go index 5ec3aace..bbd146d6 100644 --- a/en_TC/en_TC.go +++ b/en_TC/en_TC.go @@ -128,3 +128,38 @@ func (en *en_TC) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'en_TC' 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 (en *en_TC) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(en.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, en.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, en.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, en.Percent[0]) + + return b +} diff --git a/en_TK/en_TK.go b/en_TK/en_TK.go index b6da1912..d1f3f7ef 100644 --- a/en_TK/en_TK.go +++ b/en_TK/en_TK.go @@ -128,3 +128,38 @@ func (en *en_TK) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'en_TK' 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 (en *en_TK) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(en.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, en.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, en.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, en.Percent[0]) + + return b +} diff --git a/en_TO/en_TO.go b/en_TO/en_TO.go index 4318a290..98c39a56 100644 --- a/en_TO/en_TO.go +++ b/en_TO/en_TO.go @@ -128,3 +128,38 @@ func (en *en_TO) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'en_TO' 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 (en *en_TO) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(en.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, en.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, en.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, en.Percent[0]) + + return b +} diff --git a/en_TT/en_TT.go b/en_TT/en_TT.go index 8c39fcf6..e56c50a3 100644 --- a/en_TT/en_TT.go +++ b/en_TT/en_TT.go @@ -128,3 +128,38 @@ func (en *en_TT) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'en_TT' 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 (en *en_TT) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(en.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, en.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, en.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, en.Percent[0]) + + return b +} diff --git a/en_TV/en_TV.go b/en_TV/en_TV.go index fd775b87..a5ee56cf 100644 --- a/en_TV/en_TV.go +++ b/en_TV/en_TV.go @@ -128,3 +128,38 @@ func (en *en_TV) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'en_TV' 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 (en *en_TV) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(en.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, en.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, en.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, en.Percent[0]) + + return b +} diff --git a/en_TZ/en_TZ.go b/en_TZ/en_TZ.go index db2dd7c8..ce2508ac 100644 --- a/en_TZ/en_TZ.go +++ b/en_TZ/en_TZ.go @@ -128,3 +128,38 @@ func (en *en_TZ) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'en_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 (en *en_TZ) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(en.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, en.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, en.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, en.Percent[0]) + + return b +} diff --git a/en_UG/en_UG.go b/en_UG/en_UG.go index b1034f9c..08eaf06a 100644 --- a/en_UG/en_UG.go +++ b/en_UG/en_UG.go @@ -66,8 +66,8 @@ func (en *en_UG) CardinalPluralRule(num float64, v uint64) locales.PluralRule { func (en *en_UG) OrdinalPluralRule(num float64, v uint64) locales.PluralRule { n := math.Abs(num) - nMod100 := math.Mod(n, 100) nMod10 := math.Mod(n, 10) + nMod100 := math.Mod(n, 100) if nMod10 == 1 && nMod100 != 11 { return locales.PluralRuleOne @@ -128,3 +128,38 @@ func (en *en_UG) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'en_UG' 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 (en *en_UG) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(en.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, en.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, en.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, en.Percent[0]) + + return b +} diff --git a/en_UM/en_UM.go b/en_UM/en_UM.go index 9024068c..5e798064 100644 --- a/en_UM/en_UM.go +++ b/en_UM/en_UM.go @@ -66,8 +66,8 @@ func (en *en_UM) CardinalPluralRule(num float64, v uint64) locales.PluralRule { func (en *en_UM) OrdinalPluralRule(num float64, v uint64) locales.PluralRule { n := math.Abs(num) - nMod10 := math.Mod(n, 10) nMod100 := math.Mod(n, 100) + nMod10 := math.Mod(n, 10) if nMod10 == 1 && nMod100 != 11 { return locales.PluralRuleOne @@ -128,3 +128,38 @@ func (en *en_UM) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'en_UM' 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 (en *en_UM) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(en.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, en.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, en.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, en.Percent[0]) + + return b +} diff --git a/en_US/en_US.go b/en_US/en_US.go index 0897990a..1225c540 100644 --- a/en_US/en_US.go +++ b/en_US/en_US.go @@ -128,3 +128,38 @@ func (en *en_US) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'en_US' 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 (en *en_US) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(en.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, en.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, en.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, en.Percent[0]) + + return b +} diff --git a/en_US_POSIX/en_US_POSIX.go b/en_US_POSIX/en_US_POSIX.go index 266fe518..82baddc0 100644 --- a/en_US_POSIX/en_US_POSIX.go +++ b/en_US_POSIX/en_US_POSIX.go @@ -116,3 +116,38 @@ func (en *en_US_POSIX) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'en_US_POSIX' 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 (en *en_US_POSIX) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(en.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, en.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, en.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, en.Percent[0]) + + return b +} diff --git a/en_VC/en_VC.go b/en_VC/en_VC.go index 639bba9e..f9ef8fe6 100644 --- a/en_VC/en_VC.go +++ b/en_VC/en_VC.go @@ -128,3 +128,38 @@ func (en *en_VC) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'en_VC' 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 (en *en_VC) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(en.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, en.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, en.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, en.Percent[0]) + + return b +} diff --git a/en_VG/en_VG.go b/en_VG/en_VG.go index 3794c5a3..f8e6b40d 100644 --- a/en_VG/en_VG.go +++ b/en_VG/en_VG.go @@ -128,3 +128,38 @@ func (en *en_VG) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'en_VG' 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 (en *en_VG) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(en.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, en.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, en.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, en.Percent[0]) + + return b +} diff --git a/en_VI/en_VI.go b/en_VI/en_VI.go index 272dcf35..38cd777d 100644 --- a/en_VI/en_VI.go +++ b/en_VI/en_VI.go @@ -128,3 +128,38 @@ func (en *en_VI) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'en_VI' 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 (en *en_VI) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(en.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, en.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, en.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, en.Percent[0]) + + return b +} diff --git a/en_VU/en_VU.go b/en_VU/en_VU.go index ae797ea1..12cd28e0 100644 --- a/en_VU/en_VU.go +++ b/en_VU/en_VU.go @@ -66,8 +66,8 @@ func (en *en_VU) CardinalPluralRule(num float64, v uint64) locales.PluralRule { func (en *en_VU) OrdinalPluralRule(num float64, v uint64) locales.PluralRule { n := math.Abs(num) - nMod100 := math.Mod(n, 100) nMod10 := math.Mod(n, 10) + nMod100 := math.Mod(n, 100) if nMod10 == 1 && nMod100 != 11 { return locales.PluralRuleOne @@ -128,3 +128,38 @@ func (en *en_VU) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'en_VU' 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 (en *en_VU) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(en.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, en.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, en.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, en.Percent[0]) + + return b +} diff --git a/en_WS/en_WS.go b/en_WS/en_WS.go index f979243e..0c715e87 100644 --- a/en_WS/en_WS.go +++ b/en_WS/en_WS.go @@ -128,3 +128,38 @@ func (en *en_WS) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'en_WS' 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 (en *en_WS) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(en.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, en.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, en.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, en.Percent[0]) + + return b +} diff --git a/en_ZA/en_ZA.go b/en_ZA/en_ZA.go index d7ce3f1c..68fae488 100644 --- a/en_ZA/en_ZA.go +++ b/en_ZA/en_ZA.go @@ -131,3 +131,38 @@ func (en *en_ZA) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'en_ZA' 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 (en *en_ZA) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(en.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, en.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, en.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, en.Percent[0]) + + return b +} diff --git a/en_ZM/en_ZM.go b/en_ZM/en_ZM.go index 81c3dbd4..0c4a0e05 100644 --- a/en_ZM/en_ZM.go +++ b/en_ZM/en_ZM.go @@ -128,3 +128,38 @@ func (en *en_ZM) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'en_ZM' 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 (en *en_ZM) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(en.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, en.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, en.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, en.Percent[0]) + + return b +} diff --git a/en_ZW/en_ZW.go b/en_ZW/en_ZW.go index 784a9e4c..c318a881 100644 --- a/en_ZW/en_ZW.go +++ b/en_ZW/en_ZW.go @@ -66,8 +66,8 @@ func (en *en_ZW) CardinalPluralRule(num float64, v uint64) locales.PluralRule { func (en *en_ZW) OrdinalPluralRule(num float64, v uint64) locales.PluralRule { n := math.Abs(num) - nMod100 := math.Mod(n, 100) nMod10 := math.Mod(n, 10) + nMod100 := math.Mod(n, 100) if nMod10 == 1 && nMod100 != 11 { return locales.PluralRuleOne @@ -128,3 +128,38 @@ func (en *en_ZW) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'en_ZW' 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 (en *en_ZW) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(en.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, en.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, en.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, en.Percent[0]) + + return b +} @@ -119,3 +119,40 @@ func (eo *eo) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'eo' 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 (eo *eo) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(eo.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, eo.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(eo.minus) - 1; j >= 0; j-- { + b = append(b, eo.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, eo.Percent[0]) + + return b +} diff --git a/eo_001/eo_001.go b/eo_001/eo_001.go index e0f7fedd..3ae72616 100644 --- a/eo_001/eo_001.go +++ b/eo_001/eo_001.go @@ -119,3 +119,40 @@ func (eo *eo_001) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'eo_001' 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 (eo *eo_001) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(eo.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, eo.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(eo.minus) - 1; j >= 0; j-- { + b = append(b, eo.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, eo.Percent[0]) + + return b +} @@ -114,3 +114,38 @@ func (es *es) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'es' 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 (es *es) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(es.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, es.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, es.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, es.Percent[0]) + + return b +} diff --git a/es_419/es_419.go b/es_419/es_419.go index 50d50322..5c7f91d1 100644 --- a/es_419/es_419.go +++ b/es_419/es_419.go @@ -114,3 +114,38 @@ func (es *es_419) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'es_419' 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 (es *es_419) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(es.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, es.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, es.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, es.Percent[0]) + + return b +} diff --git a/es_AR/es_AR.go b/es_AR/es_AR.go index d00d1a8b..b334a750 100644 --- a/es_AR/es_AR.go +++ b/es_AR/es_AR.go @@ -114,3 +114,38 @@ func (es *es_AR) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'es_AR' 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 (es *es_AR) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(es.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, es.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, es.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, es.Percent[0]) + + return b +} diff --git a/es_BO/es_BO.go b/es_BO/es_BO.go index a7a98cd7..2d0c77b5 100644 --- a/es_BO/es_BO.go +++ b/es_BO/es_BO.go @@ -114,3 +114,38 @@ func (es *es_BO) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'es_BO' 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 (es *es_BO) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(es.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, es.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, es.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, es.Percent[0]) + + return b +} diff --git a/es_BR/es_BR.go b/es_BR/es_BR.go index 798e1d41..fa8c9272 100644 --- a/es_BR/es_BR.go +++ b/es_BR/es_BR.go @@ -114,3 +114,38 @@ func (es *es_BR) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'es_BR' 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 (es *es_BR) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(es.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, es.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, es.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, es.Percent[0]) + + return b +} diff --git a/es_CL/es_CL.go b/es_CL/es_CL.go index a1db66b4..1272cd83 100644 --- a/es_CL/es_CL.go +++ b/es_CL/es_CL.go @@ -114,3 +114,38 @@ func (es *es_CL) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'es_CL' 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 (es *es_CL) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(es.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, es.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, es.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, es.Percent[0]) + + return b +} diff --git a/es_CO/es_CO.go b/es_CO/es_CO.go index f6ae6212..b79c7b97 100644 --- a/es_CO/es_CO.go +++ b/es_CO/es_CO.go @@ -114,3 +114,38 @@ func (es *es_CO) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'es_CO' 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 (es *es_CO) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(es.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, es.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, es.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, es.Percent[0]) + + return b +} diff --git a/es_CR/es_CR.go b/es_CR/es_CR.go index b1371395..dc23782f 100644 --- a/es_CR/es_CR.go +++ b/es_CR/es_CR.go @@ -117,3 +117,38 @@ func (es *es_CR) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'es_CR' 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 (es *es_CR) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(es.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, es.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, es.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, es.Percent[0]) + + return b +} diff --git a/es_CU/es_CU.go b/es_CU/es_CU.go index 3e9dcd94..10355084 100644 --- a/es_CU/es_CU.go +++ b/es_CU/es_CU.go @@ -114,3 +114,38 @@ func (es *es_CU) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'es_CU' 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 (es *es_CU) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(es.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, es.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, es.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, es.Percent[0]) + + return b +} diff --git a/es_DO/es_DO.go b/es_DO/es_DO.go index 08bfaeb3..1ef64f34 100644 --- a/es_DO/es_DO.go +++ b/es_DO/es_DO.go @@ -114,3 +114,38 @@ func (es *es_DO) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'es_DO' 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 (es *es_DO) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(es.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, es.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, es.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, es.Percent[0]) + + return b +} diff --git a/es_EA/es_EA.go b/es_EA/es_EA.go index 91ae4cf2..b809584e 100644 --- a/es_EA/es_EA.go +++ b/es_EA/es_EA.go @@ -114,3 +114,38 @@ func (es *es_EA) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'es_EA' 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 (es *es_EA) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(es.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, es.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, es.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, es.Percent[0]) + + return b +} diff --git a/es_EC/es_EC.go b/es_EC/es_EC.go index 8ae865de..1250d0d5 100644 --- a/es_EC/es_EC.go +++ b/es_EC/es_EC.go @@ -114,3 +114,38 @@ func (es *es_EC) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'es_EC' 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 (es *es_EC) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(es.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, es.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, es.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, es.Percent[0]) + + return b +} diff --git a/es_ES/es_ES.go b/es_ES/es_ES.go index 4fddacc9..5861b2a8 100644 --- a/es_ES/es_ES.go +++ b/es_ES/es_ES.go @@ -114,3 +114,38 @@ func (es *es_ES) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'es_ES' 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 (es *es_ES) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(es.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, es.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, es.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, es.Percent[0]) + + return b +} diff --git a/es_GQ/es_GQ.go b/es_GQ/es_GQ.go index 42385ffd..eed6a0c2 100644 --- a/es_GQ/es_GQ.go +++ b/es_GQ/es_GQ.go @@ -114,3 +114,38 @@ func (es *es_GQ) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'es_GQ' 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 (es *es_GQ) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(es.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, es.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, es.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, es.Percent[0]) + + return b +} diff --git a/es_GT/es_GT.go b/es_GT/es_GT.go index e3d0e71a..0c883b0b 100644 --- a/es_GT/es_GT.go +++ b/es_GT/es_GT.go @@ -114,3 +114,38 @@ func (es *es_GT) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'es_GT' 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 (es *es_GT) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(es.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, es.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, es.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, es.Percent[0]) + + return b +} diff --git a/es_HN/es_HN.go b/es_HN/es_HN.go index fceb5702..ee83a3f3 100644 --- a/es_HN/es_HN.go +++ b/es_HN/es_HN.go @@ -114,3 +114,38 @@ func (es *es_HN) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'es_HN' 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 (es *es_HN) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(es.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, es.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, es.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, es.Percent[0]) + + return b +} diff --git a/es_IC/es_IC.go b/es_IC/es_IC.go index 49ba46a2..87d2a5c4 100644 --- a/es_IC/es_IC.go +++ b/es_IC/es_IC.go @@ -114,3 +114,38 @@ func (es *es_IC) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'es_IC' 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 (es *es_IC) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(es.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, es.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, es.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, es.Percent[0]) + + return b +} diff --git a/es_MX/es_MX.go b/es_MX/es_MX.go index c6776a97..80863471 100644 --- a/es_MX/es_MX.go +++ b/es_MX/es_MX.go @@ -114,3 +114,38 @@ func (es *es_MX) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'es_MX' 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 (es *es_MX) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(es.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, es.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, es.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, es.Percent[0]) + + return b +} diff --git a/es_NI/es_NI.go b/es_NI/es_NI.go index ec202312..9cb62070 100644 --- a/es_NI/es_NI.go +++ b/es_NI/es_NI.go @@ -114,3 +114,38 @@ func (es *es_NI) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'es_NI' 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 (es *es_NI) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(es.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, es.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, es.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, es.Percent[0]) + + return b +} diff --git a/es_PA/es_PA.go b/es_PA/es_PA.go index 49f999fe..7d282b4d 100644 --- a/es_PA/es_PA.go +++ b/es_PA/es_PA.go @@ -114,3 +114,38 @@ func (es *es_PA) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'es_PA' 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 (es *es_PA) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(es.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, es.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, es.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, es.Percent[0]) + + return b +} diff --git a/es_PE/es_PE.go b/es_PE/es_PE.go index 3d5a570e..5a5468b2 100644 --- a/es_PE/es_PE.go +++ b/es_PE/es_PE.go @@ -114,3 +114,38 @@ func (es *es_PE) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'es_PE' 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 (es *es_PE) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(es.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, es.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, es.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, es.Percent[0]) + + return b +} diff --git a/es_PH/es_PH.go b/es_PH/es_PH.go index b6da810a..b71757f5 100644 --- a/es_PH/es_PH.go +++ b/es_PH/es_PH.go @@ -114,3 +114,38 @@ func (es *es_PH) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'es_PH' 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 (es *es_PH) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(es.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, es.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, es.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, es.Percent[0]) + + return b +} diff --git a/es_PR/es_PR.go b/es_PR/es_PR.go index 620e07f4..468869ca 100644 --- a/es_PR/es_PR.go +++ b/es_PR/es_PR.go @@ -114,3 +114,38 @@ func (es *es_PR) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'es_PR' 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 (es *es_PR) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(es.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, es.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, es.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, es.Percent[0]) + + return b +} diff --git a/es_PY/es_PY.go b/es_PY/es_PY.go index 9d5fec9d..e0e59e4e 100644 --- a/es_PY/es_PY.go +++ b/es_PY/es_PY.go @@ -114,3 +114,38 @@ func (es *es_PY) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'es_PY' 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 (es *es_PY) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(es.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, es.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, es.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, es.Percent[0]) + + return b +} diff --git a/es_SV/es_SV.go b/es_SV/es_SV.go index cfd2e186..b37c328e 100644 --- a/es_SV/es_SV.go +++ b/es_SV/es_SV.go @@ -114,3 +114,38 @@ func (es *es_SV) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'es_SV' 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 (es *es_SV) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(es.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, es.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, es.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, es.Percent[0]) + + return b +} diff --git a/es_US/es_US.go b/es_US/es_US.go index e4827a0f..1962045d 100644 --- a/es_US/es_US.go +++ b/es_US/es_US.go @@ -114,3 +114,38 @@ func (es *es_US) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'es_US' 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 (es *es_US) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(es.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, es.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, es.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, es.Percent[0]) + + return b +} diff --git a/es_UY/es_UY.go b/es_UY/es_UY.go index 4e4c6faf..2376695b 100644 --- a/es_UY/es_UY.go +++ b/es_UY/es_UY.go @@ -114,3 +114,38 @@ func (es *es_UY) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'es_UY' 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 (es *es_UY) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(es.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, es.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, es.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, es.Percent[0]) + + return b +} diff --git a/es_VE/es_VE.go b/es_VE/es_VE.go index 3118ecd0..128c01f2 100644 --- a/es_VE/es_VE.go +++ b/es_VE/es_VE.go @@ -114,3 +114,38 @@ func (es *es_VE) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'es_VE' 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 (es *es_VE) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(es.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, es.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, es.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, es.Percent[0]) + + return b +} @@ -120,3 +120,40 @@ func (et *et) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'et' 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 (et *et) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(et.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, et.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(et.minus) - 1; j >= 0; j-- { + b = append(b, et.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, et.Percent[0]) + + return b +} diff --git a/et_EE/et_EE.go b/et_EE/et_EE.go index 390fa386..eca73a6d 100644 --- a/et_EE/et_EE.go +++ b/et_EE/et_EE.go @@ -120,3 +120,40 @@ func (et *et_EE) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'et_EE' 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 (et *et_EE) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(et.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, et.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(et.minus) - 1; j >= 0; j-- { + b = append(b, et.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, et.Percent[0]) + + return b +} @@ -114,3 +114,38 @@ func (eu *eu) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'eu' 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 (eu *eu) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(eu.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, eu.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, eu.minus[0]) + } + + b = append(b, eu.Percent[0]) + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + return b +} diff --git a/eu_ES/eu_ES.go b/eu_ES/eu_ES.go index 581e9779..9fdacb1e 100644 --- a/eu_ES/eu_ES.go +++ b/eu_ES/eu_ES.go @@ -114,3 +114,38 @@ func (eu *eu_ES) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'eu_ES' 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 (eu *eu_ES) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(eu.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, eu.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, eu.minus[0]) + } + + b = append(b, eu.Percent[0]) + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + return b +} @@ -112,3 +112,42 @@ func (ewo *ewo) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'ewo' 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 (ewo *ewo) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(ewo.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, ewo.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(ewo.minus) - 1; j >= 0; j-- { + b = append(b, ewo.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + for j := len(ewo.percent) - 1; j >= 0; j-- { + b = append(b, ewo.percent[j]) + } + + return b +} diff --git a/ewo_CM/ewo_CM.go b/ewo_CM/ewo_CM.go index 9d263090..b56f2a41 100644 --- a/ewo_CM/ewo_CM.go +++ b/ewo_CM/ewo_CM.go @@ -112,3 +112,42 @@ func (ewo *ewo_CM) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'ewo_CM' 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 (ewo *ewo_CM) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(ewo.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, ewo.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(ewo.minus) - 1; j >= 0; j-- { + b = append(b, ewo.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + for j := len(ewo.percent) - 1; j >= 0; j-- { + b = append(b, ewo.percent[j]) + } + + return b +} @@ -123,3 +123,45 @@ func (fa *fa) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'fa' 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 (fa *fa) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(fa.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + for j := len(fa.decimal) - 1; j >= 0; j-- { + b = append(b, fa.decimal[j]) + } + + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(fa.minus) - 1; j >= 0; j-- { + b = append(b, fa.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + for j := len(fa.percent) - 1; j >= 0; j-- { + b = append(b, fa.percent[j]) + } + + return b +} diff --git a/fa_AF/fa_AF.go b/fa_AF/fa_AF.go index 3ab4734e..dc56cac1 100644 --- a/fa_AF/fa_AF.go +++ b/fa_AF/fa_AF.go @@ -123,3 +123,45 @@ func (fa *fa_AF) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'fa_AF' 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 (fa *fa_AF) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(fa.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + for j := len(fa.decimal) - 1; j >= 0; j-- { + b = append(b, fa.decimal[j]) + } + + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(fa.minus) - 1; j >= 0; j-- { + b = append(b, fa.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + for j := len(fa.percent) - 1; j >= 0; j-- { + b = append(b, fa.percent[j]) + } + + return b +} diff --git a/fa_IR/fa_IR.go b/fa_IR/fa_IR.go index 8a990ba9..7690f690 100644 --- a/fa_IR/fa_IR.go +++ b/fa_IR/fa_IR.go @@ -123,3 +123,45 @@ func (fa *fa_IR) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'fa_IR' 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 (fa *fa_IR) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(fa.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + for j := len(fa.decimal) - 1; j >= 0; j-- { + b = append(b, fa.decimal[j]) + } + + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(fa.minus) - 1; j >= 0; j-- { + b = append(b, fa.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + for j := len(fa.percent) - 1; j >= 0; j-- { + b = append(b, fa.percent[j]) + } + + return b +} @@ -80,3 +80,13 @@ func (ff *ff) 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 'ff' 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 (ff *ff) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + return []byte(s) +} diff --git a/ff_CM/ff_CM.go b/ff_CM/ff_CM.go index c2dab8e9..c41c7843 100644 --- a/ff_CM/ff_CM.go +++ b/ff_CM/ff_CM.go @@ -80,3 +80,13 @@ func (ff *ff_CM) 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 'ff_CM' 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 (ff *ff_CM) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + return []byte(s) +} diff --git a/ff_GN/ff_GN.go b/ff_GN/ff_GN.go index c52c59cf..7e8e4ceb 100644 --- a/ff_GN/ff_GN.go +++ b/ff_GN/ff_GN.go @@ -80,3 +80,13 @@ func (ff *ff_GN) 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 'ff_GN' 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 (ff *ff_GN) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + return []byte(s) +} diff --git a/ff_MR/ff_MR.go b/ff_MR/ff_MR.go index b97ce017..b5537cf5 100644 --- a/ff_MR/ff_MR.go +++ b/ff_MR/ff_MR.go @@ -80,3 +80,13 @@ func (ff *ff_MR) 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 'ff_MR' 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 (ff *ff_MR) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + return []byte(s) +} diff --git a/ff_SN/ff_SN.go b/ff_SN/ff_SN.go index b6f5eb8d..5b8aa8a4 100644 --- a/ff_SN/ff_SN.go +++ b/ff_SN/ff_SN.go @@ -80,3 +80,13 @@ func (ff *ff_SN) 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 'ff_SN' 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 (ff *ff_SN) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + return []byte(s) +} @@ -120,3 +120,40 @@ func (fi *fi) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'fi' 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 (fi *fi) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(fi.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, fi.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(fi.minus) - 1; j >= 0; j-- { + b = append(b, fi.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, fi.Percent[0]) + + return b +} diff --git a/fi_FI/fi_FI.go b/fi_FI/fi_FI.go index fa8bfce8..120e3bd1 100644 --- a/fi_FI/fi_FI.go +++ b/fi_FI/fi_FI.go @@ -120,3 +120,40 @@ func (fi *fi_FI) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'fi_FI' 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 (fi *fi_FI) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(fi.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, fi.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(fi.minus) - 1; j >= 0; j-- { + b = append(b, fi.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, fi.Percent[0]) + + return b +} @@ -138,3 +138,38 @@ func (fil *fil) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'fil' 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 (fil *fil) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(fil.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, fil.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, fil.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, fil.Percent[0]) + + return b +} diff --git a/fil_PH/fil_PH.go b/fil_PH/fil_PH.go index ba6b85b9..35ffdacc 100644 --- a/fil_PH/fil_PH.go +++ b/fil_PH/fil_PH.go @@ -138,3 +138,38 @@ func (fil *fil_PH) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'fil_PH' 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 (fil *fil_PH) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(fil.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, fil.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, fil.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, fil.Percent[0]) + + return b +} @@ -116,3 +116,40 @@ func (fo *fo) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'fo' 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 (fo *fo) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(fo.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, fo.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(fo.minus) - 1; j >= 0; j-- { + b = append(b, fo.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, fo.Percent[0]) + + return b +} diff --git a/fo_DK/fo_DK.go b/fo_DK/fo_DK.go index 48d06fc2..7d3a2a55 100644 --- a/fo_DK/fo_DK.go +++ b/fo_DK/fo_DK.go @@ -116,3 +116,40 @@ func (fo *fo_DK) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'fo_DK' 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 (fo *fo_DK) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(fo.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, fo.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(fo.minus) - 1; j >= 0; j-- { + b = append(b, fo.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, fo.Percent[0]) + + return b +} diff --git a/fo_FO/fo_FO.go b/fo_FO/fo_FO.go index 08cdee64..37cf7b21 100644 --- a/fo_FO/fo_FO.go +++ b/fo_FO/fo_FO.go @@ -116,3 +116,40 @@ func (fo *fo_FO) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'fo_FO' 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 (fo *fo_FO) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(fo.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, fo.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(fo.minus) - 1; j >= 0; j-- { + b = append(b, fo.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, fo.Percent[0]) + + return b +} @@ -141,3 +141,45 @@ func (fr *fr) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'fr' 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 (fr *fr) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(fr.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + for j := len(fr.decimal) - 1; j >= 0; j-- { + b = append(b, fr.decimal[j]) + } + + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(fr.minus) - 1; j >= 0; j-- { + b = append(b, fr.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + for j := len(fr.percent) - 1; j >= 0; j-- { + b = append(b, fr.percent[j]) + } + + return b +} diff --git a/fr_BE/fr_BE.go b/fr_BE/fr_BE.go index 87210ccb..b12cc6bf 100644 --- a/fr_BE/fr_BE.go +++ b/fr_BE/fr_BE.go @@ -138,3 +138,45 @@ func (fr *fr_BE) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'fr_BE' 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 (fr *fr_BE) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(fr.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + for j := len(fr.decimal) - 1; j >= 0; j-- { + b = append(b, fr.decimal[j]) + } + + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(fr.minus) - 1; j >= 0; j-- { + b = append(b, fr.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + for j := len(fr.percent) - 1; j >= 0; j-- { + b = append(b, fr.percent[j]) + } + + return b +} diff --git a/fr_BF/fr_BF.go b/fr_BF/fr_BF.go index 69b14fe2..eeadd299 100644 --- a/fr_BF/fr_BF.go +++ b/fr_BF/fr_BF.go @@ -141,3 +141,45 @@ func (fr *fr_BF) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'fr_BF' 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 (fr *fr_BF) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(fr.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + for j := len(fr.decimal) - 1; j >= 0; j-- { + b = append(b, fr.decimal[j]) + } + + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(fr.minus) - 1; j >= 0; j-- { + b = append(b, fr.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + for j := len(fr.percent) - 1; j >= 0; j-- { + b = append(b, fr.percent[j]) + } + + return b +} diff --git a/fr_BI/fr_BI.go b/fr_BI/fr_BI.go index 9a36c366..1e845381 100644 --- a/fr_BI/fr_BI.go +++ b/fr_BI/fr_BI.go @@ -141,3 +141,45 @@ func (fr *fr_BI) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'fr_BI' 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 (fr *fr_BI) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(fr.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + for j := len(fr.decimal) - 1; j >= 0; j-- { + b = append(b, fr.decimal[j]) + } + + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(fr.minus) - 1; j >= 0; j-- { + b = append(b, fr.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + for j := len(fr.percent) - 1; j >= 0; j-- { + b = append(b, fr.percent[j]) + } + + return b +} diff --git a/fr_BJ/fr_BJ.go b/fr_BJ/fr_BJ.go index bf337938..b0f511c0 100644 --- a/fr_BJ/fr_BJ.go +++ b/fr_BJ/fr_BJ.go @@ -141,3 +141,45 @@ func (fr *fr_BJ) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'fr_BJ' 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 (fr *fr_BJ) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(fr.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + for j := len(fr.decimal) - 1; j >= 0; j-- { + b = append(b, fr.decimal[j]) + } + + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(fr.minus) - 1; j >= 0; j-- { + b = append(b, fr.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + for j := len(fr.percent) - 1; j >= 0; j-- { + b = append(b, fr.percent[j]) + } + + return b +} diff --git a/fr_BL/fr_BL.go b/fr_BL/fr_BL.go index cac5fd5b..2c4d9b1b 100644 --- a/fr_BL/fr_BL.go +++ b/fr_BL/fr_BL.go @@ -141,3 +141,45 @@ func (fr *fr_BL) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'fr_BL' 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 (fr *fr_BL) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(fr.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + for j := len(fr.decimal) - 1; j >= 0; j-- { + b = append(b, fr.decimal[j]) + } + + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(fr.minus) - 1; j >= 0; j-- { + b = append(b, fr.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + for j := len(fr.percent) - 1; j >= 0; j-- { + b = append(b, fr.percent[j]) + } + + return b +} diff --git a/fr_CA/fr_CA.go b/fr_CA/fr_CA.go index f2a00932..51b8bf71 100644 --- a/fr_CA/fr_CA.go +++ b/fr_CA/fr_CA.go @@ -141,3 +141,45 @@ func (fr *fr_CA) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'fr_CA' 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 (fr *fr_CA) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(fr.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + for j := len(fr.decimal) - 1; j >= 0; j-- { + b = append(b, fr.decimal[j]) + } + + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(fr.minus) - 1; j >= 0; j-- { + b = append(b, fr.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + for j := len(fr.percent) - 1; j >= 0; j-- { + b = append(b, fr.percent[j]) + } + + return b +} diff --git a/fr_CD/fr_CD.go b/fr_CD/fr_CD.go index ae83cc58..0a8a8b8a 100644 --- a/fr_CD/fr_CD.go +++ b/fr_CD/fr_CD.go @@ -141,3 +141,45 @@ func (fr *fr_CD) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'fr_CD' 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 (fr *fr_CD) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(fr.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + for j := len(fr.decimal) - 1; j >= 0; j-- { + b = append(b, fr.decimal[j]) + } + + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(fr.minus) - 1; j >= 0; j-- { + b = append(b, fr.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + for j := len(fr.percent) - 1; j >= 0; j-- { + b = append(b, fr.percent[j]) + } + + return b +} diff --git a/fr_CF/fr_CF.go b/fr_CF/fr_CF.go index ab19f504..4af95843 100644 --- a/fr_CF/fr_CF.go +++ b/fr_CF/fr_CF.go @@ -141,3 +141,45 @@ func (fr *fr_CF) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'fr_CF' 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 (fr *fr_CF) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(fr.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + for j := len(fr.decimal) - 1; j >= 0; j-- { + b = append(b, fr.decimal[j]) + } + + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(fr.minus) - 1; j >= 0; j-- { + b = append(b, fr.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + for j := len(fr.percent) - 1; j >= 0; j-- { + b = append(b, fr.percent[j]) + } + + return b +} diff --git a/fr_CG/fr_CG.go b/fr_CG/fr_CG.go index 61e3bbd4..b7c78a97 100644 --- a/fr_CG/fr_CG.go +++ b/fr_CG/fr_CG.go @@ -141,3 +141,45 @@ func (fr *fr_CG) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'fr_CG' 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 (fr *fr_CG) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(fr.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + for j := len(fr.decimal) - 1; j >= 0; j-- { + b = append(b, fr.decimal[j]) + } + + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(fr.minus) - 1; j >= 0; j-- { + b = append(b, fr.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + for j := len(fr.percent) - 1; j >= 0; j-- { + b = append(b, fr.percent[j]) + } + + return b +} diff --git a/fr_CH/fr_CH.go b/fr_CH/fr_CH.go index accc0cdd..7aecfe1b 100644 --- a/fr_CH/fr_CH.go +++ b/fr_CH/fr_CH.go @@ -138,3 +138,42 @@ func (fr *fr_CH) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'fr_CH' 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 (fr *fr_CH) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(fr.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, fr.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(fr.minus) - 1; j >= 0; j-- { + b = append(b, fr.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + for j := len(fr.percent) - 1; j >= 0; j-- { + b = append(b, fr.percent[j]) + } + + return b +} diff --git a/fr_CI/fr_CI.go b/fr_CI/fr_CI.go index e396001b..7859b121 100644 --- a/fr_CI/fr_CI.go +++ b/fr_CI/fr_CI.go @@ -141,3 +141,45 @@ func (fr *fr_CI) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'fr_CI' 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 (fr *fr_CI) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(fr.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + for j := len(fr.decimal) - 1; j >= 0; j-- { + b = append(b, fr.decimal[j]) + } + + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(fr.minus) - 1; j >= 0; j-- { + b = append(b, fr.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + for j := len(fr.percent) - 1; j >= 0; j-- { + b = append(b, fr.percent[j]) + } + + return b +} diff --git a/fr_CM/fr_CM.go b/fr_CM/fr_CM.go index fc9b1422..df8ae8e6 100644 --- a/fr_CM/fr_CM.go +++ b/fr_CM/fr_CM.go @@ -141,3 +141,45 @@ func (fr *fr_CM) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'fr_CM' 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 (fr *fr_CM) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(fr.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + for j := len(fr.decimal) - 1; j >= 0; j-- { + b = append(b, fr.decimal[j]) + } + + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(fr.minus) - 1; j >= 0; j-- { + b = append(b, fr.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + for j := len(fr.percent) - 1; j >= 0; j-- { + b = append(b, fr.percent[j]) + } + + return b +} diff --git a/fr_DJ/fr_DJ.go b/fr_DJ/fr_DJ.go index c1124e9a..f587f9b1 100644 --- a/fr_DJ/fr_DJ.go +++ b/fr_DJ/fr_DJ.go @@ -141,3 +141,45 @@ func (fr *fr_DJ) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'fr_DJ' 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 (fr *fr_DJ) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(fr.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + for j := len(fr.decimal) - 1; j >= 0; j-- { + b = append(b, fr.decimal[j]) + } + + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(fr.minus) - 1; j >= 0; j-- { + b = append(b, fr.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + for j := len(fr.percent) - 1; j >= 0; j-- { + b = append(b, fr.percent[j]) + } + + return b +} diff --git a/fr_DZ/fr_DZ.go b/fr_DZ/fr_DZ.go index 84314e20..5ba23673 100644 --- a/fr_DZ/fr_DZ.go +++ b/fr_DZ/fr_DZ.go @@ -141,3 +141,45 @@ func (fr *fr_DZ) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'fr_DZ' 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 (fr *fr_DZ) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(fr.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + for j := len(fr.decimal) - 1; j >= 0; j-- { + b = append(b, fr.decimal[j]) + } + + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(fr.minus) - 1; j >= 0; j-- { + b = append(b, fr.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + for j := len(fr.percent) - 1; j >= 0; j-- { + b = append(b, fr.percent[j]) + } + + return b +} diff --git a/fr_FR/fr_FR.go b/fr_FR/fr_FR.go index 917500b9..eaf24599 100644 --- a/fr_FR/fr_FR.go +++ b/fr_FR/fr_FR.go @@ -141,3 +141,45 @@ func (fr *fr_FR) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'fr_FR' 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 (fr *fr_FR) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(fr.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + for j := len(fr.decimal) - 1; j >= 0; j-- { + b = append(b, fr.decimal[j]) + } + + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(fr.minus) - 1; j >= 0; j-- { + b = append(b, fr.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + for j := len(fr.percent) - 1; j >= 0; j-- { + b = append(b, fr.percent[j]) + } + + return b +} diff --git a/fr_GA/fr_GA.go b/fr_GA/fr_GA.go index aa41211f..ddfcb2bf 100644 --- a/fr_GA/fr_GA.go +++ b/fr_GA/fr_GA.go @@ -141,3 +141,45 @@ func (fr *fr_GA) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'fr_GA' 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 (fr *fr_GA) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(fr.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + for j := len(fr.decimal) - 1; j >= 0; j-- { + b = append(b, fr.decimal[j]) + } + + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(fr.minus) - 1; j >= 0; j-- { + b = append(b, fr.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + for j := len(fr.percent) - 1; j >= 0; j-- { + b = append(b, fr.percent[j]) + } + + return b +} diff --git a/fr_GF/fr_GF.go b/fr_GF/fr_GF.go index c9477a0a..d1566cc8 100644 --- a/fr_GF/fr_GF.go +++ b/fr_GF/fr_GF.go @@ -141,3 +141,45 @@ func (fr *fr_GF) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'fr_GF' 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 (fr *fr_GF) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(fr.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + for j := len(fr.decimal) - 1; j >= 0; j-- { + b = append(b, fr.decimal[j]) + } + + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(fr.minus) - 1; j >= 0; j-- { + b = append(b, fr.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + for j := len(fr.percent) - 1; j >= 0; j-- { + b = append(b, fr.percent[j]) + } + + return b +} diff --git a/fr_GN/fr_GN.go b/fr_GN/fr_GN.go index d0e2ac01..8b6f1a71 100644 --- a/fr_GN/fr_GN.go +++ b/fr_GN/fr_GN.go @@ -141,3 +141,45 @@ func (fr *fr_GN) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'fr_GN' 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 (fr *fr_GN) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(fr.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + for j := len(fr.decimal) - 1; j >= 0; j-- { + b = append(b, fr.decimal[j]) + } + + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(fr.minus) - 1; j >= 0; j-- { + b = append(b, fr.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + for j := len(fr.percent) - 1; j >= 0; j-- { + b = append(b, fr.percent[j]) + } + + return b +} diff --git a/fr_GP/fr_GP.go b/fr_GP/fr_GP.go index 2c64c554..3f57cbf8 100644 --- a/fr_GP/fr_GP.go +++ b/fr_GP/fr_GP.go @@ -141,3 +141,45 @@ func (fr *fr_GP) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'fr_GP' 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 (fr *fr_GP) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(fr.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + for j := len(fr.decimal) - 1; j >= 0; j-- { + b = append(b, fr.decimal[j]) + } + + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(fr.minus) - 1; j >= 0; j-- { + b = append(b, fr.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + for j := len(fr.percent) - 1; j >= 0; j-- { + b = append(b, fr.percent[j]) + } + + return b +} diff --git a/fr_GQ/fr_GQ.go b/fr_GQ/fr_GQ.go index 4f782568..6b0da5ab 100644 --- a/fr_GQ/fr_GQ.go +++ b/fr_GQ/fr_GQ.go @@ -141,3 +141,45 @@ func (fr *fr_GQ) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'fr_GQ' 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 (fr *fr_GQ) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(fr.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + for j := len(fr.decimal) - 1; j >= 0; j-- { + b = append(b, fr.decimal[j]) + } + + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(fr.minus) - 1; j >= 0; j-- { + b = append(b, fr.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + for j := len(fr.percent) - 1; j >= 0; j-- { + b = append(b, fr.percent[j]) + } + + return b +} diff --git a/fr_HT/fr_HT.go b/fr_HT/fr_HT.go index 9deac34c..01de250e 100644 --- a/fr_HT/fr_HT.go +++ b/fr_HT/fr_HT.go @@ -141,3 +141,45 @@ func (fr *fr_HT) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'fr_HT' 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 (fr *fr_HT) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(fr.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + for j := len(fr.decimal) - 1; j >= 0; j-- { + b = append(b, fr.decimal[j]) + } + + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(fr.minus) - 1; j >= 0; j-- { + b = append(b, fr.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + for j := len(fr.percent) - 1; j >= 0; j-- { + b = append(b, fr.percent[j]) + } + + return b +} diff --git a/fr_KM/fr_KM.go b/fr_KM/fr_KM.go index 1c51dc21..b0c5c2df 100644 --- a/fr_KM/fr_KM.go +++ b/fr_KM/fr_KM.go @@ -141,3 +141,45 @@ func (fr *fr_KM) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'fr_KM' 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 (fr *fr_KM) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(fr.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + for j := len(fr.decimal) - 1; j >= 0; j-- { + b = append(b, fr.decimal[j]) + } + + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(fr.minus) - 1; j >= 0; j-- { + b = append(b, fr.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + for j := len(fr.percent) - 1; j >= 0; j-- { + b = append(b, fr.percent[j]) + } + + return b +} diff --git a/fr_LU/fr_LU.go b/fr_LU/fr_LU.go index 5086c161..78d1e1f0 100644 --- a/fr_LU/fr_LU.go +++ b/fr_LU/fr_LU.go @@ -138,3 +138,45 @@ func (fr *fr_LU) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'fr_LU' 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 (fr *fr_LU) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(fr.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + for j := len(fr.decimal) - 1; j >= 0; j-- { + b = append(b, fr.decimal[j]) + } + + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(fr.minus) - 1; j >= 0; j-- { + b = append(b, fr.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + for j := len(fr.percent) - 1; j >= 0; j-- { + b = append(b, fr.percent[j]) + } + + return b +} diff --git a/fr_MA/fr_MA.go b/fr_MA/fr_MA.go index 244535ec..1ad3a41b 100644 --- a/fr_MA/fr_MA.go +++ b/fr_MA/fr_MA.go @@ -138,3 +138,45 @@ func (fr *fr_MA) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'fr_MA' 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 (fr *fr_MA) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(fr.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + for j := len(fr.decimal) - 1; j >= 0; j-- { + b = append(b, fr.decimal[j]) + } + + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(fr.minus) - 1; j >= 0; j-- { + b = append(b, fr.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + for j := len(fr.percent) - 1; j >= 0; j-- { + b = append(b, fr.percent[j]) + } + + return b +} diff --git a/fr_MC/fr_MC.go b/fr_MC/fr_MC.go index a3c7de9b..3d251418 100644 --- a/fr_MC/fr_MC.go +++ b/fr_MC/fr_MC.go @@ -141,3 +141,45 @@ func (fr *fr_MC) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'fr_MC' 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 (fr *fr_MC) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(fr.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + for j := len(fr.decimal) - 1; j >= 0; j-- { + b = append(b, fr.decimal[j]) + } + + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(fr.minus) - 1; j >= 0; j-- { + b = append(b, fr.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + for j := len(fr.percent) - 1; j >= 0; j-- { + b = append(b, fr.percent[j]) + } + + return b +} diff --git a/fr_MF/fr_MF.go b/fr_MF/fr_MF.go index 0c25e9e5..abf90c9a 100644 --- a/fr_MF/fr_MF.go +++ b/fr_MF/fr_MF.go @@ -141,3 +141,45 @@ func (fr *fr_MF) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'fr_MF' 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 (fr *fr_MF) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(fr.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + for j := len(fr.decimal) - 1; j >= 0; j-- { + b = append(b, fr.decimal[j]) + } + + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(fr.minus) - 1; j >= 0; j-- { + b = append(b, fr.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + for j := len(fr.percent) - 1; j >= 0; j-- { + b = append(b, fr.percent[j]) + } + + return b +} diff --git a/fr_MG/fr_MG.go b/fr_MG/fr_MG.go index ec819be5..a099a3b0 100644 --- a/fr_MG/fr_MG.go +++ b/fr_MG/fr_MG.go @@ -141,3 +141,45 @@ func (fr *fr_MG) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'fr_MG' 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 (fr *fr_MG) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(fr.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + for j := len(fr.decimal) - 1; j >= 0; j-- { + b = append(b, fr.decimal[j]) + } + + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(fr.minus) - 1; j >= 0; j-- { + b = append(b, fr.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + for j := len(fr.percent) - 1; j >= 0; j-- { + b = append(b, fr.percent[j]) + } + + return b +} diff --git a/fr_ML/fr_ML.go b/fr_ML/fr_ML.go index 1ba23c6f..d2f7f723 100644 --- a/fr_ML/fr_ML.go +++ b/fr_ML/fr_ML.go @@ -141,3 +141,45 @@ func (fr *fr_ML) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'fr_ML' 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 (fr *fr_ML) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(fr.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + for j := len(fr.decimal) - 1; j >= 0; j-- { + b = append(b, fr.decimal[j]) + } + + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(fr.minus) - 1; j >= 0; j-- { + b = append(b, fr.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + for j := len(fr.percent) - 1; j >= 0; j-- { + b = append(b, fr.percent[j]) + } + + return b +} diff --git a/fr_MQ/fr_MQ.go b/fr_MQ/fr_MQ.go index 9a7aceeb..050bba78 100644 --- a/fr_MQ/fr_MQ.go +++ b/fr_MQ/fr_MQ.go @@ -141,3 +141,45 @@ func (fr *fr_MQ) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'fr_MQ' 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 (fr *fr_MQ) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(fr.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + for j := len(fr.decimal) - 1; j >= 0; j-- { + b = append(b, fr.decimal[j]) + } + + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(fr.minus) - 1; j >= 0; j-- { + b = append(b, fr.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + for j := len(fr.percent) - 1; j >= 0; j-- { + b = append(b, fr.percent[j]) + } + + return b +} diff --git a/fr_MR/fr_MR.go b/fr_MR/fr_MR.go index 441cfd87..1e848e62 100644 --- a/fr_MR/fr_MR.go +++ b/fr_MR/fr_MR.go @@ -141,3 +141,45 @@ func (fr *fr_MR) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'fr_MR' 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 (fr *fr_MR) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(fr.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + for j := len(fr.decimal) - 1; j >= 0; j-- { + b = append(b, fr.decimal[j]) + } + + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(fr.minus) - 1; j >= 0; j-- { + b = append(b, fr.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + for j := len(fr.percent) - 1; j >= 0; j-- { + b = append(b, fr.percent[j]) + } + + return b +} diff --git a/fr_MU/fr_MU.go b/fr_MU/fr_MU.go index 15c091ba..fed1ea57 100644 --- a/fr_MU/fr_MU.go +++ b/fr_MU/fr_MU.go @@ -141,3 +141,45 @@ func (fr *fr_MU) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'fr_MU' 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 (fr *fr_MU) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(fr.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + for j := len(fr.decimal) - 1; j >= 0; j-- { + b = append(b, fr.decimal[j]) + } + + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(fr.minus) - 1; j >= 0; j-- { + b = append(b, fr.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + for j := len(fr.percent) - 1; j >= 0; j-- { + b = append(b, fr.percent[j]) + } + + return b +} diff --git a/fr_NC/fr_NC.go b/fr_NC/fr_NC.go index 7055b90b..3effb97d 100644 --- a/fr_NC/fr_NC.go +++ b/fr_NC/fr_NC.go @@ -141,3 +141,45 @@ func (fr *fr_NC) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'fr_NC' 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 (fr *fr_NC) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(fr.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + for j := len(fr.decimal) - 1; j >= 0; j-- { + b = append(b, fr.decimal[j]) + } + + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(fr.minus) - 1; j >= 0; j-- { + b = append(b, fr.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + for j := len(fr.percent) - 1; j >= 0; j-- { + b = append(b, fr.percent[j]) + } + + return b +} diff --git a/fr_NE/fr_NE.go b/fr_NE/fr_NE.go index 9709d4c7..039949ee 100644 --- a/fr_NE/fr_NE.go +++ b/fr_NE/fr_NE.go @@ -141,3 +141,45 @@ func (fr *fr_NE) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'fr_NE' 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 (fr *fr_NE) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(fr.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + for j := len(fr.decimal) - 1; j >= 0; j-- { + b = append(b, fr.decimal[j]) + } + + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(fr.minus) - 1; j >= 0; j-- { + b = append(b, fr.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + for j := len(fr.percent) - 1; j >= 0; j-- { + b = append(b, fr.percent[j]) + } + + return b +} diff --git a/fr_PF/fr_PF.go b/fr_PF/fr_PF.go index 9c9c60ac..fd4d7ead 100644 --- a/fr_PF/fr_PF.go +++ b/fr_PF/fr_PF.go @@ -141,3 +141,45 @@ func (fr *fr_PF) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'fr_PF' 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 (fr *fr_PF) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(fr.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + for j := len(fr.decimal) - 1; j >= 0; j-- { + b = append(b, fr.decimal[j]) + } + + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(fr.minus) - 1; j >= 0; j-- { + b = append(b, fr.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + for j := len(fr.percent) - 1; j >= 0; j-- { + b = append(b, fr.percent[j]) + } + + return b +} diff --git a/fr_PM/fr_PM.go b/fr_PM/fr_PM.go index 71ffd4a1..4ade7d19 100644 --- a/fr_PM/fr_PM.go +++ b/fr_PM/fr_PM.go @@ -141,3 +141,45 @@ func (fr *fr_PM) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'fr_PM' 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 (fr *fr_PM) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(fr.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + for j := len(fr.decimal) - 1; j >= 0; j-- { + b = append(b, fr.decimal[j]) + } + + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(fr.minus) - 1; j >= 0; j-- { + b = append(b, fr.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + for j := len(fr.percent) - 1; j >= 0; j-- { + b = append(b, fr.percent[j]) + } + + return b +} diff --git a/fr_RE/fr_RE.go b/fr_RE/fr_RE.go index 76d438e4..c093cc76 100644 --- a/fr_RE/fr_RE.go +++ b/fr_RE/fr_RE.go @@ -141,3 +141,45 @@ func (fr *fr_RE) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'fr_RE' 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 (fr *fr_RE) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(fr.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + for j := len(fr.decimal) - 1; j >= 0; j-- { + b = append(b, fr.decimal[j]) + } + + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(fr.minus) - 1; j >= 0; j-- { + b = append(b, fr.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + for j := len(fr.percent) - 1; j >= 0; j-- { + b = append(b, fr.percent[j]) + } + + return b +} diff --git a/fr_RW/fr_RW.go b/fr_RW/fr_RW.go index 8a8a8d94..e2b64631 100644 --- a/fr_RW/fr_RW.go +++ b/fr_RW/fr_RW.go @@ -141,3 +141,45 @@ func (fr *fr_RW) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'fr_RW' 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 (fr *fr_RW) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(fr.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + for j := len(fr.decimal) - 1; j >= 0; j-- { + b = append(b, fr.decimal[j]) + } + + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(fr.minus) - 1; j >= 0; j-- { + b = append(b, fr.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + for j := len(fr.percent) - 1; j >= 0; j-- { + b = append(b, fr.percent[j]) + } + + return b +} diff --git a/fr_SC/fr_SC.go b/fr_SC/fr_SC.go index f76475fa..4ac3fede 100644 --- a/fr_SC/fr_SC.go +++ b/fr_SC/fr_SC.go @@ -141,3 +141,45 @@ func (fr *fr_SC) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'fr_SC' 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 (fr *fr_SC) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(fr.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + for j := len(fr.decimal) - 1; j >= 0; j-- { + b = append(b, fr.decimal[j]) + } + + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(fr.minus) - 1; j >= 0; j-- { + b = append(b, fr.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + for j := len(fr.percent) - 1; j >= 0; j-- { + b = append(b, fr.percent[j]) + } + + return b +} diff --git a/fr_SN/fr_SN.go b/fr_SN/fr_SN.go index 5172c257..6c0b1552 100644 --- a/fr_SN/fr_SN.go +++ b/fr_SN/fr_SN.go @@ -141,3 +141,45 @@ func (fr *fr_SN) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'fr_SN' 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 (fr *fr_SN) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(fr.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + for j := len(fr.decimal) - 1; j >= 0; j-- { + b = append(b, fr.decimal[j]) + } + + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(fr.minus) - 1; j >= 0; j-- { + b = append(b, fr.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + for j := len(fr.percent) - 1; j >= 0; j-- { + b = append(b, fr.percent[j]) + } + + return b +} diff --git a/fr_SY/fr_SY.go b/fr_SY/fr_SY.go index 1cb6e52d..0d9596ec 100644 --- a/fr_SY/fr_SY.go +++ b/fr_SY/fr_SY.go @@ -141,3 +141,45 @@ func (fr *fr_SY) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'fr_SY' 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 (fr *fr_SY) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(fr.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + for j := len(fr.decimal) - 1; j >= 0; j-- { + b = append(b, fr.decimal[j]) + } + + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(fr.minus) - 1; j >= 0; j-- { + b = append(b, fr.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + for j := len(fr.percent) - 1; j >= 0; j-- { + b = append(b, fr.percent[j]) + } + + return b +} diff --git a/fr_TD/fr_TD.go b/fr_TD/fr_TD.go index 6a2c032a..dfe75855 100644 --- a/fr_TD/fr_TD.go +++ b/fr_TD/fr_TD.go @@ -141,3 +141,45 @@ func (fr *fr_TD) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'fr_TD' 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 (fr *fr_TD) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(fr.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + for j := len(fr.decimal) - 1; j >= 0; j-- { + b = append(b, fr.decimal[j]) + } + + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(fr.minus) - 1; j >= 0; j-- { + b = append(b, fr.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + for j := len(fr.percent) - 1; j >= 0; j-- { + b = append(b, fr.percent[j]) + } + + return b +} diff --git a/fr_TG/fr_TG.go b/fr_TG/fr_TG.go index f08e9ed4..5ca59b6b 100644 --- a/fr_TG/fr_TG.go +++ b/fr_TG/fr_TG.go @@ -141,3 +141,45 @@ func (fr *fr_TG) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'fr_TG' 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 (fr *fr_TG) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(fr.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + for j := len(fr.decimal) - 1; j >= 0; j-- { + b = append(b, fr.decimal[j]) + } + + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(fr.minus) - 1; j >= 0; j-- { + b = append(b, fr.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + for j := len(fr.percent) - 1; j >= 0; j-- { + b = append(b, fr.percent[j]) + } + + return b +} diff --git a/fr_TN/fr_TN.go b/fr_TN/fr_TN.go index ebe58795..148f808e 100644 --- a/fr_TN/fr_TN.go +++ b/fr_TN/fr_TN.go @@ -141,3 +141,45 @@ func (fr *fr_TN) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'fr_TN' 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 (fr *fr_TN) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(fr.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + for j := len(fr.decimal) - 1; j >= 0; j-- { + b = append(b, fr.decimal[j]) + } + + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(fr.minus) - 1; j >= 0; j-- { + b = append(b, fr.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + for j := len(fr.percent) - 1; j >= 0; j-- { + b = append(b, fr.percent[j]) + } + + return b +} diff --git a/fr_VU/fr_VU.go b/fr_VU/fr_VU.go index 01a7e8c7..b5096058 100644 --- a/fr_VU/fr_VU.go +++ b/fr_VU/fr_VU.go @@ -141,3 +141,45 @@ func (fr *fr_VU) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'fr_VU' 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 (fr *fr_VU) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(fr.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + for j := len(fr.decimal) - 1; j >= 0; j-- { + b = append(b, fr.decimal[j]) + } + + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(fr.minus) - 1; j >= 0; j-- { + b = append(b, fr.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + for j := len(fr.percent) - 1; j >= 0; j-- { + b = append(b, fr.percent[j]) + } + + return b +} diff --git a/fr_WF/fr_WF.go b/fr_WF/fr_WF.go index c77be043..84285bf8 100644 --- a/fr_WF/fr_WF.go +++ b/fr_WF/fr_WF.go @@ -141,3 +141,45 @@ func (fr *fr_WF) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'fr_WF' 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 (fr *fr_WF) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(fr.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + for j := len(fr.decimal) - 1; j >= 0; j-- { + b = append(b, fr.decimal[j]) + } + + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(fr.minus) - 1; j >= 0; j-- { + b = append(b, fr.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + for j := len(fr.percent) - 1; j >= 0; j-- { + b = append(b, fr.percent[j]) + } + + return b +} diff --git a/fr_YT/fr_YT.go b/fr_YT/fr_YT.go index 5fa75ae6..7ed93546 100644 --- a/fr_YT/fr_YT.go +++ b/fr_YT/fr_YT.go @@ -141,3 +141,45 @@ func (fr *fr_YT) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'fr_YT' 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 (fr *fr_YT) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(fr.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + for j := len(fr.decimal) - 1; j >= 0; j-- { + b = append(b, fr.decimal[j]) + } + + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(fr.minus) - 1; j >= 0; j-- { + b = append(b, fr.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + for j := len(fr.percent) - 1; j >= 0; j-- { + b = append(b, fr.percent[j]) + } + + return b +} @@ -114,3 +114,38 @@ func (fur *fur) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'fur' 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 (fur *fur) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(fur.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, fur.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, fur.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, fur.Percent[0]) + + return b +} diff --git a/fur_IT/fur_IT.go b/fur_IT/fur_IT.go index 42e49c2a..c6752f39 100644 --- a/fur_IT/fur_IT.go +++ b/fur_IT/fur_IT.go @@ -114,3 +114,38 @@ func (fur *fur_IT) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'fur_IT' 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 (fur *fur_IT) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(fur.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, fur.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, fur.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, fur.Percent[0]) + + return b +} @@ -115,3 +115,38 @@ func (fy *fy) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'fy' 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 (fy *fy) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(fy.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, fy.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, fy.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, fy.Percent[0]) + + return b +} diff --git a/fy_NL/fy_NL.go b/fy_NL/fy_NL.go index dfea04c0..b0ce3765 100644 --- a/fy_NL/fy_NL.go +++ b/fy_NL/fy_NL.go @@ -115,3 +115,38 @@ func (fy *fy_NL) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'fy_NL' 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 (fy *fy_NL) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(fy.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, fy.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, fy.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, fy.Percent[0]) + + return b +} @@ -127,3 +127,38 @@ func (ga *ga) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'ga' 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 (ga *ga) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(ga.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, ga.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, ga.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, ga.Percent[0]) + + return b +} diff --git a/ga_IE/ga_IE.go b/ga_IE/ga_IE.go index f209344f..5fcf6f52 100644 --- a/ga_IE/ga_IE.go +++ b/ga_IE/ga_IE.go @@ -127,3 +127,38 @@ func (ga *ga_IE) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'ga_IE' 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 (ga *ga_IE) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(ga.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, ga.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, ga.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, ga.Percent[0]) + + return b +} @@ -126,3 +126,45 @@ func (gd *gd) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'gd' 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 (gd *gd) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(gd.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + for j := len(gd.decimal) - 1; j >= 0; j-- { + b = append(b, gd.decimal[j]) + } + + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(gd.minus) - 1; j >= 0; j-- { + b = append(b, gd.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + for j := len(gd.percent) - 1; j >= 0; j-- { + b = append(b, gd.percent[j]) + } + + return b +} diff --git a/gd_GB/gd_GB.go b/gd_GB/gd_GB.go index a43aade2..2ec35780 100644 --- a/gd_GB/gd_GB.go +++ b/gd_GB/gd_GB.go @@ -126,3 +126,45 @@ func (gd *gd_GB) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'gd_GB' 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 (gd *gd_GB) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(gd.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + for j := len(gd.decimal) - 1; j >= 0; j-- { + b = append(b, gd.decimal[j]) + } + + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(gd.minus) - 1; j >= 0; j-- { + b = append(b, gd.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + for j := len(gd.percent) - 1; j >= 0; j-- { + b = append(b, gd.percent[j]) + } + + return b +} @@ -126,3 +126,38 @@ func (gl *gl) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'gl' 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 (gl *gl) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(gl.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, gl.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, gl.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, gl.Percent[0]) + + return b +} diff --git a/gl_ES/gl_ES.go b/gl_ES/gl_ES.go index d25e0cf5..a56c161b 100644 --- a/gl_ES/gl_ES.go +++ b/gl_ES/gl_ES.go @@ -126,3 +126,38 @@ func (gl *gl_ES) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'gl_ES' 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 (gl *gl_ES) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(gl.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, gl.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, gl.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, gl.Percent[0]) + + return b +} @@ -119,3 +119,40 @@ func (gsw *gsw) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'gsw' 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 (gsw *gsw) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(gsw.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, gsw.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(gsw.minus) - 1; j >= 0; j-- { + b = append(b, gsw.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, gsw.Percent[0]) + + return b +} diff --git a/gsw_CH/gsw_CH.go b/gsw_CH/gsw_CH.go index 7b147c6c..4ae64261 100644 --- a/gsw_CH/gsw_CH.go +++ b/gsw_CH/gsw_CH.go @@ -119,3 +119,40 @@ func (gsw *gsw_CH) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'gsw_CH' 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 (gsw *gsw_CH) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(gsw.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, gsw.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(gsw.minus) - 1; j >= 0; j-- { + b = append(b, gsw.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, gsw.Percent[0]) + + return b +} diff --git a/gsw_FR/gsw_FR.go b/gsw_FR/gsw_FR.go index 4f0ef0dd..cb100a02 100644 --- a/gsw_FR/gsw_FR.go +++ b/gsw_FR/gsw_FR.go @@ -119,3 +119,40 @@ func (gsw *gsw_FR) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'gsw_FR' 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 (gsw *gsw_FR) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(gsw.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, gsw.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(gsw.minus) - 1; j >= 0; j-- { + b = append(b, gsw.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, gsw.Percent[0]) + + return b +} diff --git a/gsw_LI/gsw_LI.go b/gsw_LI/gsw_LI.go index ffe9f4e5..fbc31abd 100644 --- a/gsw_LI/gsw_LI.go +++ b/gsw_LI/gsw_LI.go @@ -119,3 +119,40 @@ func (gsw *gsw_LI) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'gsw_LI' 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 (gsw *gsw_LI) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(gsw.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, gsw.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(gsw.minus) - 1; j >= 0; j-- { + b = append(b, gsw.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, gsw.Percent[0]) + + return b +} @@ -156,3 +156,45 @@ func (gu *gu) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'gu' 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 (gu *gu) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(gu.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + for j := len(gu.decimal) - 1; j >= 0; j-- { + b = append(b, gu.decimal[j]) + } + + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(gu.minus) - 1; j >= 0; j-- { + b = append(b, gu.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + for j := len(gu.percent) - 1; j >= 0; j-- { + b = append(b, gu.percent[j]) + } + + return b +} diff --git a/gu_IN/gu_IN.go b/gu_IN/gu_IN.go index 64ca445c..0342ceee 100644 --- a/gu_IN/gu_IN.go +++ b/gu_IN/gu_IN.go @@ -156,3 +156,45 @@ func (gu *gu_IN) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'gu_IN' 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 (gu *gu_IN) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(gu.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + for j := len(gu.decimal) - 1; j >= 0; j-- { + b = append(b, gu.decimal[j]) + } + + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(gu.minus) - 1; j >= 0; j-- { + b = append(b, gu.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + for j := len(gu.percent) - 1; j >= 0; j-- { + b = append(b, gu.percent[j]) + } + + return b +} @@ -72,3 +72,13 @@ func (guz *guz) 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 'guz' 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 (guz *guz) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + return []byte(s) +} diff --git a/guz_KE/guz_KE.go b/guz_KE/guz_KE.go index 2519bdf1..2832cd83 100644 --- a/guz_KE/guz_KE.go +++ b/guz_KE/guz_KE.go @@ -72,3 +72,13 @@ func (guz *guz_KE) 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 'guz_KE' 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 (guz *guz_KE) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + return []byte(s) +} @@ -88,3 +88,13 @@ func (gv *gv) 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 'gv' 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 (gv *gv) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + return []byte(s) +} diff --git a/gv_IM/gv_IM.go b/gv_IM/gv_IM.go index 38ac77e6..6ab9bf26 100644 --- a/gv_IM/gv_IM.go +++ b/gv_IM/gv_IM.go @@ -88,3 +88,13 @@ func (gv *gv_IM) 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 'gv_IM' 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 (gv *gv_IM) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + return []byte(s) +} @@ -116,3 +116,42 @@ func (ha *ha) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'ha' 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 (ha *ha) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(ha.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, ha.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(ha.minus) - 1; j >= 0; j-- { + b = append(b, ha.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + for j := len(ha.percent) - 1; j >= 0; j-- { + b = append(b, ha.percent[j]) + } + + return b +} diff --git a/ha_GH/ha_GH.go b/ha_GH/ha_GH.go index 1d5de856..ac90020f 100644 --- a/ha_GH/ha_GH.go +++ b/ha_GH/ha_GH.go @@ -116,3 +116,42 @@ func (ha *ha_GH) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'ha_GH' 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 (ha *ha_GH) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(ha.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, ha.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(ha.minus) - 1; j >= 0; j-- { + b = append(b, ha.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + for j := len(ha.percent) - 1; j >= 0; j-- { + b = append(b, ha.percent[j]) + } + + return b +} diff --git a/ha_NE/ha_NE.go b/ha_NE/ha_NE.go index 3d59f342..8b16b9c7 100644 --- a/ha_NE/ha_NE.go +++ b/ha_NE/ha_NE.go @@ -116,3 +116,42 @@ func (ha *ha_NE) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'ha_NE' 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 (ha *ha_NE) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(ha.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, ha.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(ha.minus) - 1; j >= 0; j-- { + b = append(b, ha.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + for j := len(ha.percent) - 1; j >= 0; j-- { + b = append(b, ha.percent[j]) + } + + return b +} diff --git a/ha_NG/ha_NG.go b/ha_NG/ha_NG.go index 31fd84bc..15e7cc3e 100644 --- a/ha_NG/ha_NG.go +++ b/ha_NG/ha_NG.go @@ -116,3 +116,42 @@ func (ha *ha_NG) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'ha_NG' 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 (ha *ha_NG) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(ha.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, ha.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(ha.minus) - 1; j >= 0; j-- { + b = append(b, ha.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + for j := len(ha.percent) - 1; j >= 0; j-- { + b = append(b, ha.percent[j]) + } + + return b +} @@ -79,3 +79,13 @@ func (haw *haw) 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 'haw' 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 (haw *haw) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + return []byte(s) +} diff --git a/haw_US/haw_US.go b/haw_US/haw_US.go index f77e3032..2c2403a8 100644 --- a/haw_US/haw_US.go +++ b/haw_US/haw_US.go @@ -79,3 +79,13 @@ func (haw *haw_US) 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 'haw_US' 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 (haw *haw_US) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + return []byte(s) +} @@ -149,3 +149,40 @@ func (he *he) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'he' 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 (he *he) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(he.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, he.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(he.minus) - 1; j >= 0; j-- { + b = append(b, he.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, he.Percent[0]) + + return b +} diff --git a/he_IL/he_IL.go b/he_IL/he_IL.go index 4b1e7fa0..70ce6569 100644 --- a/he_IL/he_IL.go +++ b/he_IL/he_IL.go @@ -149,3 +149,40 @@ func (he *he_IL) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'he_IL' 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 (he *he_IL) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(he.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, he.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(he.minus) - 1; j >= 0; j-- { + b = append(b, he.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, he.Percent[0]) + + return b +} @@ -148,3 +148,38 @@ func (hi *hi) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'hi' 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 (hi *hi) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(hi.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, hi.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, hi.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, hi.Percent[0]) + + return b +} diff --git a/hi_IN/hi_IN.go b/hi_IN/hi_IN.go index fc750a19..36f2d406 100644 --- a/hi_IN/hi_IN.go +++ b/hi_IN/hi_IN.go @@ -148,3 +148,38 @@ func (hi *hi_IN) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'hi_IN' 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 (hi *hi_IN) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(hi.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, hi.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, hi.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, hi.Percent[0]) + + return b +} @@ -55,8 +55,8 @@ func (hr *hr) CardinalPluralRule(num float64, v uint64) locales.PluralRule { n := math.Abs(num) i := int64(n) f := locales.F(n, v) - iMod100 := i % 100 iMod10 := i % 10 + iMod100 := i % 100 fMod10 := f % 10 fMod100 := f % 100 @@ -145,3 +145,38 @@ func (hr *hr) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'hr' 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 (hr *hr) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(hr.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, hr.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, hr.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, hr.Percent[0]) + + return b +} diff --git a/hr_BA/hr_BA.go b/hr_BA/hr_BA.go index 5ed4c3d3..6b35f8ce 100644 --- a/hr_BA/hr_BA.go +++ b/hr_BA/hr_BA.go @@ -55,8 +55,8 @@ func (hr *hr_BA) CardinalPluralRule(num float64, v uint64) locales.PluralRule { n := math.Abs(num) i := int64(n) f := locales.F(n, v) - iMod100 := i % 100 iMod10 := i % 10 + iMod100 := i % 100 fMod10 := f % 10 fMod100 := f % 100 @@ -145,3 +145,38 @@ func (hr *hr_BA) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'hr_BA' 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 (hr *hr_BA) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(hr.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, hr.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, hr.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, hr.Percent[0]) + + return b +} diff --git a/hr_HR/hr_HR.go b/hr_HR/hr_HR.go index a2f8d8bc..1419129c 100644 --- a/hr_HR/hr_HR.go +++ b/hr_HR/hr_HR.go @@ -145,3 +145,38 @@ func (hr *hr_HR) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'hr_HR' 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 (hr *hr_HR) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(hr.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, hr.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, hr.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, hr.Percent[0]) + + return b +} @@ -122,3 +122,38 @@ func (hsb *hsb) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'hsb' 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 (hsb *hsb) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(hsb.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, hsb.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, hsb.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, hsb.Percent[0]) + + return b +} diff --git a/hsb_DE/hsb_DE.go b/hsb_DE/hsb_DE.go index bda1f7da..f78f8e6a 100644 --- a/hsb_DE/hsb_DE.go +++ b/hsb_DE/hsb_DE.go @@ -122,3 +122,38 @@ func (hsb *hsb_DE) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'hsb_DE' 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 (hsb *hsb_DE) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(hsb.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, hsb.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, hsb.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, hsb.Percent[0]) + + return b +} @@ -135,3 +135,38 @@ func (hu *hu) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'hu' 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 (hu *hu) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(hu.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, hu.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, hu.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, hu.Percent[0]) + + return b +} diff --git a/hu_HU/hu_HU.go b/hu_HU/hu_HU.go index f5299154..12392254 100644 --- a/hu_HU/hu_HU.go +++ b/hu_HU/hu_HU.go @@ -135,3 +135,38 @@ func (hu *hu_HU) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'hu_HU' 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 (hu *hu_HU) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(hu.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, hu.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, hu.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, hu.Percent[0]) + + return b +} @@ -121,3 +121,38 @@ func (hy *hy) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'hy' 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 (hy *hy) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(hy.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, hy.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, hy.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, hy.Percent[0]) + + return b +} diff --git a/hy_AM/hy_AM.go b/hy_AM/hy_AM.go index ce0e3d74..a5746a0a 100644 --- a/hy_AM/hy_AM.go +++ b/hy_AM/hy_AM.go @@ -121,3 +121,38 @@ func (hy *hy_AM) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'hy_AM' 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 (hy *hy_AM) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(hy.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, hy.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, hy.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, hy.Percent[0]) + + return b +} @@ -107,3 +107,38 @@ func (id *id) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'id' 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 (id *id) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(id.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, id.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, id.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, id.Percent[0]) + + return b +} diff --git a/id_ID/id_ID.go b/id_ID/id_ID.go index 84499109..cad59254 100644 --- a/id_ID/id_ID.go +++ b/id_ID/id_ID.go @@ -107,3 +107,38 @@ func (id *id_ID) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'id_ID' 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 (id *id_ID) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(id.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, id.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, id.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, id.Percent[0]) + + return b +} @@ -72,3 +72,13 @@ func (ig *ig) 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 'ig' 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 (ig *ig) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + return []byte(s) +} diff --git a/ig_NG/ig_NG.go b/ig_NG/ig_NG.go index f07ef2d5..257d4bf7 100644 --- a/ig_NG/ig_NG.go +++ b/ig_NG/ig_NG.go @@ -72,3 +72,13 @@ func (ig *ig_NG) 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 'ig_NG' 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 (ig *ig_NG) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + return []byte(s) +} @@ -72,3 +72,13 @@ func (ii *ii) 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 'ii' 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 (ii *ii) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + return []byte(s) +} diff --git a/ii_CN/ii_CN.go b/ii_CN/ii_CN.go index 9a0a2b90..bf634540 100644 --- a/ii_CN/ii_CN.go +++ b/ii_CN/ii_CN.go @@ -72,3 +72,13 @@ func (ii *ii_CN) 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 'ii_CN' 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 (ii *ii_CN) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + return []byte(s) +} @@ -55,8 +55,8 @@ func (is *is) CardinalPluralRule(num float64, v uint64) locales.PluralRule { n := math.Abs(num) i := int64(n) t := locales.T(n, v) - iMod10 := i % 10 iMod100 := i % 100 + iMod10 := i % 10 if (t == 0 && iMod10 == 1 && iMod100 != 11) || (t != 0) { return locales.PluralRuleOne @@ -131,3 +131,38 @@ func (is *is) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'is' 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 (is *is) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(is.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, is.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, is.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, is.Percent[0]) + + return b +} diff --git a/is_IS/is_IS.go b/is_IS/is_IS.go index 5f57e7c4..5a925c7d 100644 --- a/is_IS/is_IS.go +++ b/is_IS/is_IS.go @@ -55,8 +55,8 @@ func (is *is_IS) CardinalPluralRule(num float64, v uint64) locales.PluralRule { n := math.Abs(num) i := int64(n) t := locales.T(n, v) - iMod100 := i % 100 iMod10 := i % 10 + iMod100 := i % 100 if (t == 0 && iMod10 == 1 && iMod100 != 11) || (t != 0) { return locales.PluralRuleOne @@ -131,3 +131,38 @@ func (is *is_IS) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'is_IS' 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 (is *is_IS) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(is.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, is.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, is.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, is.Percent[0]) + + return b +} @@ -133,3 +133,38 @@ func (it *it) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'it' 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 (it *it) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(it.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, it.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, it.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, it.Percent[0]) + + return b +} diff --git a/it_CH/it_CH.go b/it_CH/it_CH.go index 68a14342..90763299 100644 --- a/it_CH/it_CH.go +++ b/it_CH/it_CH.go @@ -133,3 +133,38 @@ func (it *it_CH) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'it_CH' 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 (it *it_CH) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(it.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, it.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, it.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, it.Percent[0]) + + return b +} diff --git a/it_IT/it_IT.go b/it_IT/it_IT.go index 5068d50d..6a8ff711 100644 --- a/it_IT/it_IT.go +++ b/it_IT/it_IT.go @@ -133,3 +133,38 @@ func (it *it_IT) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'it_IT' 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 (it *it_IT) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(it.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, it.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, it.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, it.Percent[0]) + + return b +} diff --git a/it_SM/it_SM.go b/it_SM/it_SM.go index 58e28412..397577f7 100644 --- a/it_SM/it_SM.go +++ b/it_SM/it_SM.go @@ -133,3 +133,38 @@ func (it *it_SM) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'it_SM' 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 (it *it_SM) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(it.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, it.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, it.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, it.Percent[0]) + + return b +} @@ -107,3 +107,38 @@ func (ja *ja) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'ja' 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 (ja *ja) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(ja.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, ja.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, ja.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, ja.Percent[0]) + + return b +} diff --git a/ja_JP/ja_JP.go b/ja_JP/ja_JP.go index c0bdda1b..5868faaa 100644 --- a/ja_JP/ja_JP.go +++ b/ja_JP/ja_JP.go @@ -107,3 +107,38 @@ func (ja *ja_JP) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'ja_JP' 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 (ja *ja_JP) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(ja.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, ja.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, ja.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, ja.Percent[0]) + + return b +} @@ -114,3 +114,38 @@ func (jgo *jgo) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'jgo' 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 (jgo *jgo) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(jgo.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, jgo.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, jgo.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, jgo.Percent[0]) + + return b +} diff --git a/jgo_CM/jgo_CM.go b/jgo_CM/jgo_CM.go index c852ee71..3b8c3ae4 100644 --- a/jgo_CM/jgo_CM.go +++ b/jgo_CM/jgo_CM.go @@ -114,3 +114,38 @@ func (jgo *jgo_CM) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'jgo_CM' 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 (jgo *jgo_CM) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(jgo.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, jgo.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, jgo.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, jgo.Percent[0]) + + return b +} @@ -79,3 +79,13 @@ func (jmc *jmc) 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 'jmc' 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 (jmc *jmc) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + return []byte(s) +} diff --git a/jmc_TZ/jmc_TZ.go b/jmc_TZ/jmc_TZ.go index 6928fcf3..cd835c7b 100644 --- a/jmc_TZ/jmc_TZ.go +++ b/jmc_TZ/jmc_TZ.go @@ -79,3 +79,13 @@ func (jmc *jmc_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 'jmc_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 (jmc *jmc_TZ) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + return []byte(s) +} @@ -139,3 +139,38 @@ func (ka *ka) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'ka' 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 (ka *ka) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(ka.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, ka.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, ka.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, ka.Percent[0]) + + return b +} diff --git a/ka_GE/ka_GE.go b/ka_GE/ka_GE.go index c9adcf7d..1a82bc05 100644 --- a/ka_GE/ka_GE.go +++ b/ka_GE/ka_GE.go @@ -139,3 +139,38 @@ func (ka *ka_GE) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'ka_GE' 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 (ka *ka_GE) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(ka.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, ka.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, ka.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, ka.Percent[0]) + + return b +} @@ -80,3 +80,13 @@ func (kab *kab) 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 'kab' 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 (kab *kab) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + return []byte(s) +} diff --git a/kab_DZ/kab_DZ.go b/kab_DZ/kab_DZ.go index 3dfcdccb..7a6a3358 100644 --- a/kab_DZ/kab_DZ.go +++ b/kab_DZ/kab_DZ.go @@ -80,3 +80,13 @@ func (kab *kab_DZ) 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 'kab_DZ' 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 (kab *kab_DZ) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + return []byte(s) +} @@ -72,3 +72,13 @@ func (kam *kam) 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 'kam' 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 (kam *kam) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + return []byte(s) +} diff --git a/kam_KE/kam_KE.go b/kam_KE/kam_KE.go index 0b63ba85..10f60f11 100644 --- a/kam_KE/kam_KE.go +++ b/kam_KE/kam_KE.go @@ -72,3 +72,13 @@ func (kam *kam_KE) 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 'kam_KE' 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 (kam *kam_KE) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + return []byte(s) +} @@ -72,3 +72,13 @@ func (kde *kde) 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 'kde' 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 (kde *kde) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + return []byte(s) +} diff --git a/kde_TZ/kde_TZ.go b/kde_TZ/kde_TZ.go index 38ed2638..4a4d44d8 100644 --- a/kde_TZ/kde_TZ.go +++ b/kde_TZ/kde_TZ.go @@ -72,3 +72,13 @@ func (kde *kde_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 'kde_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 (kde *kde_TZ) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + return []byte(s) +} @@ -110,3 +110,38 @@ func (kea *kea) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'kea' 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 (kea *kea) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(kea.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, kea.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, kea.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, kea.Percent[0]) + + return b +} diff --git a/kea_CV/kea_CV.go b/kea_CV/kea_CV.go index 030391c3..db41fc98 100644 --- a/kea_CV/kea_CV.go +++ b/kea_CV/kea_CV.go @@ -110,3 +110,38 @@ func (kea *kea_CV) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'kea_CV' 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 (kea *kea_CV) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(kea.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, kea.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, kea.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, kea.Percent[0]) + + return b +} @@ -72,3 +72,13 @@ func (khq *khq) 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 'khq' 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 (khq *khq) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + return []byte(s) +} diff --git a/khq_ML/khq_ML.go b/khq_ML/khq_ML.go index afdc4a2f..e7402da1 100644 --- a/khq_ML/khq_ML.go +++ b/khq_ML/khq_ML.go @@ -72,3 +72,13 @@ func (khq *khq_ML) 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 'khq_ML' 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 (khq *khq_ML) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + return []byte(s) +} @@ -72,3 +72,13 @@ func (ki *ki) 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 'ki' 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 (ki *ki) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + return []byte(s) +} diff --git a/ki_KE/ki_KE.go b/ki_KE/ki_KE.go index 3b823e57..8fd7aac2 100644 --- a/ki_KE/ki_KE.go +++ b/ki_KE/ki_KE.go @@ -72,3 +72,13 @@ func (ki *ki_KE) 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 'ki_KE' 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 (ki *ki_KE) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + return []byte(s) +} @@ -136,3 +136,38 @@ func (kk *kk) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'kk' 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 (kk *kk) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(kk.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, kk.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, kk.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, kk.Percent[0]) + + return b +} diff --git a/kk_KZ/kk_KZ.go b/kk_KZ/kk_KZ.go index 3ba5a55f..ba8a7b76 100644 --- a/kk_KZ/kk_KZ.go +++ b/kk_KZ/kk_KZ.go @@ -136,3 +136,38 @@ func (kk *kk_KZ) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'kk_KZ' 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 (kk *kk_KZ) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(kk.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, kk.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, kk.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, kk.Percent[0]) + + return b +} @@ -79,3 +79,13 @@ func (kkj *kkj) 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 'kkj' 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 (kkj *kkj) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + return []byte(s) +} diff --git a/kkj_CM/kkj_CM.go b/kkj_CM/kkj_CM.go index 09e3597f..833fc18b 100644 --- a/kkj_CM/kkj_CM.go +++ b/kkj_CM/kkj_CM.go @@ -79,3 +79,13 @@ func (kkj *kkj_CM) 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 'kkj_CM' 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 (kkj *kkj_CM) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + return []byte(s) +} @@ -114,3 +114,38 @@ func (kl *kl) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'kl' 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 (kl *kl) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(kl.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, kl.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, kl.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, kl.Percent[0]) + + return b +} diff --git a/kl_GL/kl_GL.go b/kl_GL/kl_GL.go index 5820966d..ca0ba389 100644 --- a/kl_GL/kl_GL.go +++ b/kl_GL/kl_GL.go @@ -114,3 +114,38 @@ func (kl *kl_GL) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'kl_GL' 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 (kl *kl_GL) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(kl.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, kl.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, kl.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, kl.Percent[0]) + + return b +} @@ -72,3 +72,13 @@ func (kln *kln) 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 'kln' 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 (kln *kln) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + return []byte(s) +} diff --git a/kln_KE/kln_KE.go b/kln_KE/kln_KE.go index 5c36bfd4..1e50f055 100644 --- a/kln_KE/kln_KE.go +++ b/kln_KE/kln_KE.go @@ -72,3 +72,13 @@ func (kln *kln_KE) 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 'kln_KE' 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 (kln *kln_KE) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + return []byte(s) +} @@ -107,3 +107,38 @@ func (km *km) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'km' 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 (km *km) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(km.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, km.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, km.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, km.Percent[0]) + + return b +} diff --git a/km_KH/km_KH.go b/km_KH/km_KH.go index 13bf38b3..c4e353a3 100644 --- a/km_KH/km_KH.go +++ b/km_KH/km_KH.go @@ -107,3 +107,38 @@ func (km *km_KH) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'km_KH' 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 (km *km_KH) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(km.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, km.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, km.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, km.Percent[0]) + + return b +} @@ -126,3 +126,38 @@ func (kn *kn) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'kn' 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 (kn *kn) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(kn.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, kn.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, kn.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, kn.Percent[0]) + + return b +} diff --git a/kn_IN/kn_IN.go b/kn_IN/kn_IN.go index 985805a0..cb1d2c18 100644 --- a/kn_IN/kn_IN.go +++ b/kn_IN/kn_IN.go @@ -126,3 +126,38 @@ func (kn *kn_IN) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'kn_IN' 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 (kn *kn_IN) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(kn.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, kn.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, kn.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, kn.Percent[0]) + + return b +} @@ -107,3 +107,38 @@ func (ko *ko) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'ko' 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 (ko *ko) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(ko.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, ko.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, ko.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, ko.Percent[0]) + + return b +} diff --git a/ko_KP/ko_KP.go b/ko_KP/ko_KP.go index a1360876..e02c38c5 100644 --- a/ko_KP/ko_KP.go +++ b/ko_KP/ko_KP.go @@ -107,3 +107,38 @@ func (ko *ko_KP) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'ko_KP' 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 (ko *ko_KP) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(ko.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, ko.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, ko.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, ko.Percent[0]) + + return b +} diff --git a/ko_KR/ko_KR.go b/ko_KR/ko_KR.go index 332a7e45..d8be162c 100644 --- a/ko_KR/ko_KR.go +++ b/ko_KR/ko_KR.go @@ -107,3 +107,38 @@ func (ko *ko_KR) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'ko_KR' 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 (ko *ko_KR) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(ko.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, ko.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, ko.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, ko.Percent[0]) + + return b +} @@ -124,3 +124,45 @@ func (kok *kok) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'kok' 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 (kok *kok) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(kok.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + for j := len(kok.decimal) - 1; j >= 0; j-- { + b = append(b, kok.decimal[j]) + } + + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(kok.minus) - 1; j >= 0; j-- { + b = append(b, kok.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + for j := len(kok.percent) - 1; j >= 0; j-- { + b = append(b, kok.percent[j]) + } + + return b +} diff --git a/kok_IN/kok_IN.go b/kok_IN/kok_IN.go index 986b1736..4d6e67e6 100644 --- a/kok_IN/kok_IN.go +++ b/kok_IN/kok_IN.go @@ -124,3 +124,45 @@ func (kok *kok_IN) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'kok_IN' 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 (kok *kok_IN) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(kok.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + for j := len(kok.decimal) - 1; j >= 0; j-- { + b = append(b, kok.decimal[j]) + } + + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(kok.minus) - 1; j >= 0; j-- { + b = append(b, kok.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + for j := len(kok.percent) - 1; j >= 0; j-- { + b = append(b, kok.percent[j]) + } + + return b +} @@ -125,3 +125,40 @@ func (ks *ks) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'ks' 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 (ks *ks) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(ks.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, ks.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(ks.minus) - 1; j >= 0; j-- { + b = append(b, ks.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, ks.Percent[0]) + + return b +} diff --git a/ks_IN/ks_IN.go b/ks_IN/ks_IN.go index 1d7b89b2..8afad801 100644 --- a/ks_IN/ks_IN.go +++ b/ks_IN/ks_IN.go @@ -125,3 +125,40 @@ func (ks *ks_IN) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'ks_IN' 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 (ks *ks_IN) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(ks.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, ks.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(ks.minus) - 1; j >= 0; j-- { + b = append(b, ks.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, ks.Percent[0]) + + return b +} @@ -79,3 +79,13 @@ func (ksb *ksb) 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 'ksb' 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 (ksb *ksb) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + return []byte(s) +} diff --git a/ksb_TZ/ksb_TZ.go b/ksb_TZ/ksb_TZ.go index 961f1a80..66289a28 100644 --- a/ksb_TZ/ksb_TZ.go +++ b/ksb_TZ/ksb_TZ.go @@ -79,3 +79,13 @@ func (ksb *ksb_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 'ksb_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 (ksb *ksb_TZ) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + return []byte(s) +} @@ -112,3 +112,13 @@ func (ksf *ksf) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'ksf' 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 (ksf *ksf) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + return []byte(s) +} diff --git a/ksf_CM/ksf_CM.go b/ksf_CM/ksf_CM.go index e547cf5d..0c90386a 100644 --- a/ksf_CM/ksf_CM.go +++ b/ksf_CM/ksf_CM.go @@ -112,3 +112,13 @@ func (ksf *ksf_CM) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'ksf_CM' 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 (ksf *ksf_CM) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + return []byte(s) +} @@ -121,3 +121,40 @@ func (ksh *ksh) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'ksh' 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 (ksh *ksh) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(ksh.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, ksh.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(ksh.minus) - 1; j >= 0; j-- { + b = append(b, ksh.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, ksh.Percent[0]) + + return b +} diff --git a/ksh_DE/ksh_DE.go b/ksh_DE/ksh_DE.go index 51085499..9b39d148 100644 --- a/ksh_DE/ksh_DE.go +++ b/ksh_DE/ksh_DE.go @@ -121,3 +121,40 @@ func (ksh *ksh_DE) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'ksh_DE' 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 (ksh *ksh_DE) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(ksh.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, ksh.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(ksh.minus) - 1; j >= 0; j-- { + b = append(b, ksh.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, ksh.Percent[0]) + + return b +} @@ -81,3 +81,13 @@ func (kw *kw) 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 'kw' 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 (kw *kw) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + return []byte(s) +} diff --git a/kw_GB/kw_GB.go b/kw_GB/kw_GB.go index 4a5b336e..83107fa2 100644 --- a/kw_GB/kw_GB.go +++ b/kw_GB/kw_GB.go @@ -81,3 +81,13 @@ func (kw *kw_GB) 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 'kw_GB' 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 (kw *kw_GB) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + return []byte(s) +} @@ -128,3 +128,38 @@ func (ky *ky) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'ky' 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 (ky *ky) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(ky.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, ky.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, ky.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, ky.Percent[0]) + + return b +} diff --git a/ky_KG/ky_KG.go b/ky_KG/ky_KG.go index 6068f668..039b27bb 100644 --- a/ky_KG/ky_KG.go +++ b/ky_KG/ky_KG.go @@ -128,3 +128,38 @@ func (ky *ky_KG) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'ky_KG' 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 (ky *ky_KG) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(ky.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, ky.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, ky.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, ky.Percent[0]) + + return b +} @@ -82,3 +82,13 @@ func (lag *lag) 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 'lag' 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 (lag *lag) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + return []byte(s) +} diff --git a/lag_TZ/lag_TZ.go b/lag_TZ/lag_TZ.go index 6f6318c7..cfe8620b 100644 --- a/lag_TZ/lag_TZ.go +++ b/lag_TZ/lag_TZ.go @@ -82,3 +82,13 @@ func (lag *lag_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 'lag_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 (lag *lag_TZ) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + return []byte(s) +} @@ -114,3 +114,38 @@ func (lb *lb) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'lb' 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 (lb *lb) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(lb.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, lb.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, lb.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, lb.Percent[0]) + + return b +} diff --git a/lb_LU/lb_LU.go b/lb_LU/lb_LU.go index d7469ad2..d7f840cc 100644 --- a/lb_LU/lb_LU.go +++ b/lb_LU/lb_LU.go @@ -114,3 +114,38 @@ func (lb *lb_LU) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'lb_LU' 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 (lb *lb_LU) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(lb.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, lb.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, lb.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, lb.Percent[0]) + + return b +} @@ -79,3 +79,13 @@ func (lg *lg) 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 'lg' 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 (lg *lg) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + return []byte(s) +} diff --git a/lg_UG/lg_UG.go b/lg_UG/lg_UG.go index 6aef1004..4d9736de 100644 --- a/lg_UG/lg_UG.go +++ b/lg_UG/lg_UG.go @@ -79,3 +79,13 @@ func (lg *lg_UG) 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 'lg_UG' 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 (lg *lg_UG) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + return []byte(s) +} @@ -72,3 +72,13 @@ func (lkt *lkt) 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 'lkt' 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 (lkt *lkt) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + return []byte(s) +} diff --git a/lkt_US/lkt_US.go b/lkt_US/lkt_US.go index 5f6e3f34..2801d382 100644 --- a/lkt_US/lkt_US.go +++ b/lkt_US/lkt_US.go @@ -72,3 +72,13 @@ func (lkt *lkt_US) 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 'lkt_US' 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 (lkt *lkt_US) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + return []byte(s) +} @@ -114,3 +114,13 @@ func (ln *ln) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'ln' 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 (ln *ln) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + return []byte(s) +} diff --git a/ln_AO/ln_AO.go b/ln_AO/ln_AO.go index 8a6c40ad..3d7e86d6 100644 --- a/ln_AO/ln_AO.go +++ b/ln_AO/ln_AO.go @@ -114,3 +114,13 @@ func (ln *ln_AO) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'ln_AO' 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 (ln *ln_AO) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + return []byte(s) +} diff --git a/ln_CD/ln_CD.go b/ln_CD/ln_CD.go index 1abe740c..d20b10e8 100644 --- a/ln_CD/ln_CD.go +++ b/ln_CD/ln_CD.go @@ -114,3 +114,13 @@ func (ln *ln_CD) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'ln_CD' 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 (ln *ln_CD) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + return []byte(s) +} diff --git a/ln_CF/ln_CF.go b/ln_CF/ln_CF.go index 802cb9e8..b605f137 100644 --- a/ln_CF/ln_CF.go +++ b/ln_CF/ln_CF.go @@ -114,3 +114,13 @@ func (ln *ln_CF) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'ln_CF' 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 (ln *ln_CF) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + return []byte(s) +} diff --git a/ln_CG/ln_CG.go b/ln_CG/ln_CG.go index a2171b61..486b6445 100644 --- a/ln_CG/ln_CG.go +++ b/ln_CG/ln_CG.go @@ -114,3 +114,13 @@ func (ln *ln_CG) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'ln_CG' 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 (ln *ln_CG) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + return []byte(s) +} @@ -79,3 +79,38 @@ func (lo *lo) 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 'lo' 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 (lo *lo) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(lo.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, lo.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, lo.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, lo.Percent[0]) + + return b +} diff --git a/lo_LA/lo_LA.go b/lo_LA/lo_LA.go index 6675c732..a6943561 100644 --- a/lo_LA/lo_LA.go +++ b/lo_LA/lo_LA.go @@ -79,3 +79,38 @@ func (lo *lo_LA) 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 'lo_LA' 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 (lo *lo_LA) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(lo.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, lo.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, lo.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, lo.Percent[0]) + + return b +} @@ -107,3 +107,38 @@ func (lrc *lrc) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'lrc' 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 (lrc *lrc) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(lrc.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, lrc.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, lrc.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, lrc.Percent[0]) + + return b +} diff --git a/lrc_IQ/lrc_IQ.go b/lrc_IQ/lrc_IQ.go index 4a09c7b7..5a422f6c 100644 --- a/lrc_IQ/lrc_IQ.go +++ b/lrc_IQ/lrc_IQ.go @@ -107,3 +107,38 @@ func (lrc *lrc_IQ) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'lrc_IQ' 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 (lrc *lrc_IQ) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(lrc.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, lrc.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, lrc.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, lrc.Percent[0]) + + return b +} diff --git a/lrc_IR/lrc_IR.go b/lrc_IR/lrc_IR.go index 01290c04..086d7edd 100644 --- a/lrc_IR/lrc_IR.go +++ b/lrc_IR/lrc_IR.go @@ -107,3 +107,38 @@ func (lrc *lrc_IR) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'lrc_IR' 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 (lrc *lrc_IR) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(lrc.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, lrc.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, lrc.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, lrc.Percent[0]) + + return b +} @@ -163,3 +163,40 @@ func (lt *lt) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'lt' 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 (lt *lt) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(lt.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, lt.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(lt.minus) - 1; j >= 0; j-- { + b = append(b, lt.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, lt.Percent[0]) + + return b +} diff --git a/lt_LT/lt_LT.go b/lt_LT/lt_LT.go index 8eb26c83..955ba6cb 100644 --- a/lt_LT/lt_LT.go +++ b/lt_LT/lt_LT.go @@ -163,3 +163,40 @@ func (lt *lt_LT) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'lt_LT' 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 (lt *lt_LT) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(lt.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, lt.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(lt.minus) - 1; j >= 0; j-- { + b = append(b, lt.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, lt.Percent[0]) + + return b +} @@ -109,3 +109,13 @@ func (lu *lu) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'lu' 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 (lu *lu) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + return []byte(s) +} diff --git a/lu_CD/lu_CD.go b/lu_CD/lu_CD.go index 45392cee..f7ccdc73 100644 --- a/lu_CD/lu_CD.go +++ b/lu_CD/lu_CD.go @@ -109,3 +109,13 @@ func (lu *lu_CD) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'lu_CD' 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 (lu *lu_CD) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + return []byte(s) +} @@ -72,3 +72,13 @@ func (luo *luo) 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 'luo' 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 (luo *luo) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + return []byte(s) +} diff --git a/luo_KE/luo_KE.go b/luo_KE/luo_KE.go index 450f6a41..68e84d7c 100644 --- a/luo_KE/luo_KE.go +++ b/luo_KE/luo_KE.go @@ -72,3 +72,13 @@ func (luo *luo_KE) 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 'luo_KE' 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 (luo *luo_KE) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + return []byte(s) +} @@ -72,3 +72,13 @@ func (luy *luy) 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 'luy' 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 (luy *luy) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + return []byte(s) +} diff --git a/luy_KE/luy_KE.go b/luy_KE/luy_KE.go index 5ee6681f..fe9bbfd8 100644 --- a/luy_KE/luy_KE.go +++ b/luy_KE/luy_KE.go @@ -72,3 +72,13 @@ func (luy *luy_KE) 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 'luy_KE' 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 (luy *luy_KE) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + return []byte(s) +} @@ -54,10 +54,10 @@ func (lv *lv) CardinalPluralRule(num float64, v uint64) locales.PluralRule { n := math.Abs(num) f := locales.F(n, v) - nMod100 := math.Mod(n, 100) nMod10 := math.Mod(n, 10) - fMod10 := f % 10 + nMod100 := math.Mod(n, 100) fMod100 := f % 100 + fMod10 := f % 10 if (nMod10 == 0) || (nMod100 >= 11 && nMod100 <= 19) || (v == 2 && fMod100 >= 11 && fMod100 <= 19) { return locales.PluralRuleZero @@ -147,3 +147,38 @@ func (lv *lv) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'lv' 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 (lv *lv) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(lv.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, lv.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, lv.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, lv.Percent[0]) + + return b +} diff --git a/lv_LV/lv_LV.go b/lv_LV/lv_LV.go index a7bfb154..2a6d5eb9 100644 --- a/lv_LV/lv_LV.go +++ b/lv_LV/lv_LV.go @@ -147,3 +147,38 @@ func (lv *lv_LV) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'lv_LV' 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 (lv *lv_LV) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(lv.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, lv.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, lv.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, lv.Percent[0]) + + return b +} @@ -79,3 +79,13 @@ func (mas *mas) 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 'mas' 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 (mas *mas) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + return []byte(s) +} diff --git a/mas_KE/mas_KE.go b/mas_KE/mas_KE.go index 4b9ca417..579c40c4 100644 --- a/mas_KE/mas_KE.go +++ b/mas_KE/mas_KE.go @@ -79,3 +79,13 @@ func (mas *mas_KE) 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 'mas_KE' 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 (mas *mas_KE) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + return []byte(s) +} diff --git a/mas_TZ/mas_TZ.go b/mas_TZ/mas_TZ.go index 2f61a0e3..1cc4fa4e 100644 --- a/mas_TZ/mas_TZ.go +++ b/mas_TZ/mas_TZ.go @@ -79,3 +79,13 @@ func (mas *mas_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 'mas_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 (mas *mas_TZ) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + return []byte(s) +} @@ -72,3 +72,13 @@ func (mer *mer) 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 'mer' 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 (mer *mer) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + return []byte(s) +} diff --git a/mer_KE/mer_KE.go b/mer_KE/mer_KE.go index 38fe3dde..89eb29ea 100644 --- a/mer_KE/mer_KE.go +++ b/mer_KE/mer_KE.go @@ -72,3 +72,13 @@ func (mer *mer_KE) 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 'mer_KE' 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 (mer *mer_KE) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + return []byte(s) +} @@ -72,3 +72,13 @@ func (mfe *mfe) 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 'mfe' 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 (mfe *mfe) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + return []byte(s) +} diff --git a/mfe_MU/mfe_MU.go b/mfe_MU/mfe_MU.go index 646968ac..d4dad986 100644 --- a/mfe_MU/mfe_MU.go +++ b/mfe_MU/mfe_MU.go @@ -72,3 +72,13 @@ func (mfe *mfe_MU) 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 'mfe_MU' 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 (mfe *mfe_MU) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + return []byte(s) +} @@ -79,3 +79,13 @@ func (mg *mg) 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 'mg' 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 (mg *mg) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + return []byte(s) +} diff --git a/mg_MG/mg_MG.go b/mg_MG/mg_MG.go index 34e9299c..463dc2ba 100644 --- a/mg_MG/mg_MG.go +++ b/mg_MG/mg_MG.go @@ -79,3 +79,13 @@ func (mg *mg_MG) 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 'mg_MG' 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 (mg *mg_MG) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + return []byte(s) +} @@ -72,3 +72,13 @@ func (mgh *mgh) 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 'mgh' 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 (mgh *mgh) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + return []byte(s) +} diff --git a/mgh_MZ/mgh_MZ.go b/mgh_MZ/mgh_MZ.go index 8f97615d..f7ab699d 100644 --- a/mgh_MZ/mgh_MZ.go +++ b/mgh_MZ/mgh_MZ.go @@ -72,3 +72,13 @@ func (mgh *mgh_MZ) 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 'mgh_MZ' 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 (mgh *mgh_MZ) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + return []byte(s) +} @@ -114,3 +114,38 @@ func (mgo *mgo) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'mgo' 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 (mgo *mgo) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(mgo.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, mgo.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, mgo.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, mgo.Percent[0]) + + return b +} diff --git a/mgo_CM/mgo_CM.go b/mgo_CM/mgo_CM.go index d8aeb560..01e5ac9f 100644 --- a/mgo_CM/mgo_CM.go +++ b/mgo_CM/mgo_CM.go @@ -114,3 +114,38 @@ func (mgo *mgo_CM) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'mgo_CM' 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 (mgo *mgo_CM) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(mgo.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, mgo.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, mgo.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, mgo.Percent[0]) + + return b +} @@ -132,3 +132,38 @@ func (mk *mk) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'mk' 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 (mk *mk) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(mk.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, mk.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, mk.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, mk.Percent[0]) + + return b +} diff --git a/mk_MK/mk_MK.go b/mk_MK/mk_MK.go index f329688f..a1feb2b0 100644 --- a/mk_MK/mk_MK.go +++ b/mk_MK/mk_MK.go @@ -132,3 +132,38 @@ func (mk *mk_MK) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'mk_MK' 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 (mk *mk_MK) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(mk.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, mk.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, mk.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, mk.Percent[0]) + + return b +} @@ -134,3 +134,38 @@ func (ml *ml) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'ml' 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 (ml *ml) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(ml.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, ml.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, ml.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, ml.Percent[0]) + + return b +} diff --git a/ml_IN/ml_IN.go b/ml_IN/ml_IN.go index 9454f1d7..da468392 100644 --- a/ml_IN/ml_IN.go +++ b/ml_IN/ml_IN.go @@ -134,3 +134,38 @@ func (ml *ml_IN) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'ml_IN' 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 (ml *ml_IN) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(ml.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, ml.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, ml.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, ml.Percent[0]) + + return b +} @@ -125,3 +125,38 @@ func (mn *mn) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'mn' 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 (mn *mn) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(mn.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, mn.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, mn.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, mn.Percent[0]) + + return b +} diff --git a/mn_MN/mn_MN.go b/mn_MN/mn_MN.go index 1ad97244..b1d1fdaf 100644 --- a/mn_MN/mn_MN.go +++ b/mn_MN/mn_MN.go @@ -125,3 +125,38 @@ func (mn *mn_MN) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'mn_MN' 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 (mn *mn_MN) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(mn.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, mn.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, mn.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, mn.Percent[0]) + + return b +} @@ -146,3 +146,38 @@ func (mr *mr) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'mr' 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 (mr *mr) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(mr.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, mr.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, mr.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, mr.Percent[0]) + + return b +} diff --git a/mr_IN/mr_IN.go b/mr_IN/mr_IN.go index 0f87983f..6230ba2a 100644 --- a/mr_IN/mr_IN.go +++ b/mr_IN/mr_IN.go @@ -146,3 +146,38 @@ func (mr *mr_IN) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'mr_IN' 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 (mr *mr_IN) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(mr.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, mr.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, mr.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, mr.Percent[0]) + + return b +} @@ -114,3 +114,38 @@ func (ms *ms) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'ms' 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 (ms *ms) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(ms.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, ms.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, ms.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, ms.Percent[0]) + + return b +} diff --git a/ms_BN/ms_BN.go b/ms_BN/ms_BN.go index 2b4dceaa..aed5b3f0 100644 --- a/ms_BN/ms_BN.go +++ b/ms_BN/ms_BN.go @@ -114,3 +114,38 @@ func (ms *ms_BN) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'ms_BN' 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 (ms *ms_BN) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(ms.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, ms.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, ms.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, ms.Percent[0]) + + return b +} diff --git a/ms_MY/ms_MY.go b/ms_MY/ms_MY.go index 0be8b447..11e5ee62 100644 --- a/ms_MY/ms_MY.go +++ b/ms_MY/ms_MY.go @@ -114,3 +114,38 @@ func (ms *ms_MY) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'ms_MY' 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 (ms *ms_MY) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(ms.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, ms.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, ms.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, ms.Percent[0]) + + return b +} diff --git a/ms_SG/ms_SG.go b/ms_SG/ms_SG.go index 67c8992c..79e788e4 100644 --- a/ms_SG/ms_SG.go +++ b/ms_SG/ms_SG.go @@ -114,3 +114,38 @@ func (ms *ms_SG) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'ms_SG' 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 (ms *ms_SG) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(ms.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, ms.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, ms.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, ms.Percent[0]) + + return b +} @@ -119,3 +119,38 @@ func (mt *mt) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'mt' 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 (mt *mt) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(mt.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, mt.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, mt.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, mt.Percent[0]) + + return b +} diff --git a/mt_MT/mt_MT.go b/mt_MT/mt_MT.go index 7d69b2c6..4685d638 100644 --- a/mt_MT/mt_MT.go +++ b/mt_MT/mt_MT.go @@ -119,3 +119,38 @@ func (mt *mt_MT) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'mt_MT' 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 (mt *mt_MT) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(mt.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, mt.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, mt.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, mt.Percent[0]) + + return b +} @@ -109,3 +109,42 @@ func (mua *mua) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'mua' 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 (mua *mua) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(mua.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, mua.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(mua.minus) - 1; j >= 0; j-- { + b = append(b, mua.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + for j := len(mua.percent) - 1; j >= 0; j-- { + b = append(b, mua.percent[j]) + } + + return b +} diff --git a/mua_CM/mua_CM.go b/mua_CM/mua_CM.go index 28f3e437..e727e743 100644 --- a/mua_CM/mua_CM.go +++ b/mua_CM/mua_CM.go @@ -109,3 +109,42 @@ func (mua *mua_CM) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'mua_CM' 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 (mua *mua_CM) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(mua.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, mua.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(mua.minus) - 1; j >= 0; j-- { + b = append(b, mua.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + for j := len(mua.percent) - 1; j >= 0; j-- { + b = append(b, mua.percent[j]) + } + + return b +} @@ -107,3 +107,38 @@ func (my *my) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'my' 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 (my *my) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(my.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, my.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, my.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, my.Percent[0]) + + return b +} diff --git a/my_MM/my_MM.go b/my_MM/my_MM.go index f8d4f25f..2beca196 100644 --- a/my_MM/my_MM.go +++ b/my_MM/my_MM.go @@ -107,3 +107,38 @@ func (my *my_MM) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'my_MM' 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 (my *my_MM) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(my.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, my.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, my.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, my.Percent[0]) + + return b +} @@ -72,3 +72,13 @@ func (mzn *mzn) 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 'mzn' 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 (mzn *mzn) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + return []byte(s) +} diff --git a/mzn_IR/mzn_IR.go b/mzn_IR/mzn_IR.go index f1948b52..bd82b321 100644 --- a/mzn_IR/mzn_IR.go +++ b/mzn_IR/mzn_IR.go @@ -72,3 +72,13 @@ func (mzn *mzn_IR) 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 'mzn_IR' 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 (mzn *mzn_IR) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + return []byte(s) +} @@ -81,3 +81,13 @@ func (naq *naq) 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 'naq' 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 (naq *naq) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + return []byte(s) +} diff --git a/naq_NA/naq_NA.go b/naq_NA/naq_NA.go index 27b761a2..29f4d8de 100644 --- a/naq_NA/naq_NA.go +++ b/naq_NA/naq_NA.go @@ -81,3 +81,13 @@ func (naq *naq_NA) 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 'naq_NA' 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 (naq *naq_NA) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + return []byte(s) +} @@ -122,3 +122,45 @@ func (nb *nb) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'nb' 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 (nb *nb) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(nb.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + for j := len(nb.decimal) - 1; j >= 0; j-- { + b = append(b, nb.decimal[j]) + } + + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(nb.minus) - 1; j >= 0; j-- { + b = append(b, nb.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + for j := len(nb.percent) - 1; j >= 0; j-- { + b = append(b, nb.percent[j]) + } + + return b +} diff --git a/nb_NO/nb_NO.go b/nb_NO/nb_NO.go index 3ac45432..a20277dc 100644 --- a/nb_NO/nb_NO.go +++ b/nb_NO/nb_NO.go @@ -122,3 +122,45 @@ func (nb *nb_NO) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'nb_NO' 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 (nb *nb_NO) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(nb.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + for j := len(nb.decimal) - 1; j >= 0; j-- { + b = append(b, nb.decimal[j]) + } + + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(nb.minus) - 1; j >= 0; j-- { + b = append(b, nb.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + for j := len(nb.percent) - 1; j >= 0; j-- { + b = append(b, nb.percent[j]) + } + + return b +} diff --git a/nb_SJ/nb_SJ.go b/nb_SJ/nb_SJ.go index 131e1b04..c7187d88 100644 --- a/nb_SJ/nb_SJ.go +++ b/nb_SJ/nb_SJ.go @@ -122,3 +122,45 @@ func (nb *nb_SJ) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'nb_SJ' 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 (nb *nb_SJ) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(nb.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + for j := len(nb.decimal) - 1; j >= 0; j-- { + b = append(b, nb.decimal[j]) + } + + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(nb.minus) - 1; j >= 0; j-- { + b = append(b, nb.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + for j := len(nb.percent) - 1; j >= 0; j-- { + b = append(b, nb.percent[j]) + } + + return b +} @@ -79,3 +79,13 @@ func (nd *nd) 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 'nd' 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 (nd *nd) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + return []byte(s) +} diff --git a/nd_ZW/nd_ZW.go b/nd_ZW/nd_ZW.go index 36210945..a14c311b 100644 --- a/nd_ZW/nd_ZW.go +++ b/nd_ZW/nd_ZW.go @@ -79,3 +79,13 @@ func (nd *nd_ZW) 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 'nd_ZW' 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 (nd *nd_ZW) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + return []byte(s) +} @@ -132,3 +132,38 @@ func (ne *ne) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'ne' 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 (ne *ne) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(ne.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, ne.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, ne.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, ne.Percent[0]) + + return b +} diff --git a/ne_IN/ne_IN.go b/ne_IN/ne_IN.go index 8729d2e9..d159de92 100644 --- a/ne_IN/ne_IN.go +++ b/ne_IN/ne_IN.go @@ -132,3 +132,38 @@ func (ne *ne_IN) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'ne_IN' 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 (ne *ne_IN) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(ne.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, ne.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, ne.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, ne.Percent[0]) + + return b +} diff --git a/ne_NP/ne_NP.go b/ne_NP/ne_NP.go index 872e4152..11a751f6 100644 --- a/ne_NP/ne_NP.go +++ b/ne_NP/ne_NP.go @@ -132,3 +132,38 @@ func (ne *ne_NP) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'ne_NP' 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 (ne *ne_NP) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(ne.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, ne.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, ne.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, ne.Percent[0]) + + return b +} @@ -134,3 +134,45 @@ func (nl *nl) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'nl' 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 (nl *nl) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(nl.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + for j := len(nl.decimal) - 1; j >= 0; j-- { + b = append(b, nl.decimal[j]) + } + + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(nl.minus) - 1; j >= 0; j-- { + b = append(b, nl.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + for j := len(nl.percent) - 1; j >= 0; j-- { + b = append(b, nl.percent[j]) + } + + return b +} diff --git a/nl_AW/nl_AW.go b/nl_AW/nl_AW.go index 8769d324..eda9ea50 100644 --- a/nl_AW/nl_AW.go +++ b/nl_AW/nl_AW.go @@ -134,3 +134,45 @@ func (nl *nl_AW) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'nl_AW' 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 (nl *nl_AW) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(nl.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + for j := len(nl.decimal) - 1; j >= 0; j-- { + b = append(b, nl.decimal[j]) + } + + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(nl.minus) - 1; j >= 0; j-- { + b = append(b, nl.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + for j := len(nl.percent) - 1; j >= 0; j-- { + b = append(b, nl.percent[j]) + } + + return b +} diff --git a/nl_BE/nl_BE.go b/nl_BE/nl_BE.go index bde10e90..5341ecfe 100644 --- a/nl_BE/nl_BE.go +++ b/nl_BE/nl_BE.go @@ -134,3 +134,45 @@ func (nl *nl_BE) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'nl_BE' 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 (nl *nl_BE) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(nl.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + for j := len(nl.decimal) - 1; j >= 0; j-- { + b = append(b, nl.decimal[j]) + } + + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(nl.minus) - 1; j >= 0; j-- { + b = append(b, nl.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + for j := len(nl.percent) - 1; j >= 0; j-- { + b = append(b, nl.percent[j]) + } + + return b +} diff --git a/nl_BQ/nl_BQ.go b/nl_BQ/nl_BQ.go index 74f5e8e1..570ef887 100644 --- a/nl_BQ/nl_BQ.go +++ b/nl_BQ/nl_BQ.go @@ -134,3 +134,45 @@ func (nl *nl_BQ) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'nl_BQ' 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 (nl *nl_BQ) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(nl.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + for j := len(nl.decimal) - 1; j >= 0; j-- { + b = append(b, nl.decimal[j]) + } + + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(nl.minus) - 1; j >= 0; j-- { + b = append(b, nl.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + for j := len(nl.percent) - 1; j >= 0; j-- { + b = append(b, nl.percent[j]) + } + + return b +} diff --git a/nl_CW/nl_CW.go b/nl_CW/nl_CW.go index 07d66f6d..4f60e14e 100644 --- a/nl_CW/nl_CW.go +++ b/nl_CW/nl_CW.go @@ -134,3 +134,45 @@ func (nl *nl_CW) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'nl_CW' 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 (nl *nl_CW) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(nl.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + for j := len(nl.decimal) - 1; j >= 0; j-- { + b = append(b, nl.decimal[j]) + } + + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(nl.minus) - 1; j >= 0; j-- { + b = append(b, nl.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + for j := len(nl.percent) - 1; j >= 0; j-- { + b = append(b, nl.percent[j]) + } + + return b +} diff --git a/nl_NL/nl_NL.go b/nl_NL/nl_NL.go index d37a6a85..b4d08642 100644 --- a/nl_NL/nl_NL.go +++ b/nl_NL/nl_NL.go @@ -134,3 +134,45 @@ func (nl *nl_NL) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'nl_NL' 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 (nl *nl_NL) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(nl.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + for j := len(nl.decimal) - 1; j >= 0; j-- { + b = append(b, nl.decimal[j]) + } + + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(nl.minus) - 1; j >= 0; j-- { + b = append(b, nl.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + for j := len(nl.percent) - 1; j >= 0; j-- { + b = append(b, nl.percent[j]) + } + + return b +} diff --git a/nl_SR/nl_SR.go b/nl_SR/nl_SR.go index 5f5372ec..f1a2b19a 100644 --- a/nl_SR/nl_SR.go +++ b/nl_SR/nl_SR.go @@ -134,3 +134,45 @@ func (nl *nl_SR) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'nl_SR' 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 (nl *nl_SR) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(nl.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + for j := len(nl.decimal) - 1; j >= 0; j-- { + b = append(b, nl.decimal[j]) + } + + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(nl.minus) - 1; j >= 0; j-- { + b = append(b, nl.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + for j := len(nl.percent) - 1; j >= 0; j-- { + b = append(b, nl.percent[j]) + } + + return b +} diff --git a/nl_SX/nl_SX.go b/nl_SX/nl_SX.go index 758da238..14ea24f2 100644 --- a/nl_SX/nl_SX.go +++ b/nl_SX/nl_SX.go @@ -134,3 +134,45 @@ func (nl *nl_SX) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'nl_SX' 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 (nl *nl_SX) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(nl.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + for j := len(nl.decimal) - 1; j >= 0; j-- { + b = append(b, nl.decimal[j]) + } + + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(nl.minus) - 1; j >= 0; j-- { + b = append(b, nl.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + for j := len(nl.percent) - 1; j >= 0; j-- { + b = append(b, nl.percent[j]) + } + + return b +} @@ -112,3 +112,42 @@ func (nmg *nmg) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'nmg' 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 (nmg *nmg) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(nmg.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, nmg.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(nmg.minus) - 1; j >= 0; j-- { + b = append(b, nmg.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + for j := len(nmg.percent) - 1; j >= 0; j-- { + b = append(b, nmg.percent[j]) + } + + return b +} diff --git a/nmg_CM/nmg_CM.go b/nmg_CM/nmg_CM.go index fc1c6152..12d98168 100644 --- a/nmg_CM/nmg_CM.go +++ b/nmg_CM/nmg_CM.go @@ -112,3 +112,42 @@ func (nmg *nmg_CM) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'nmg_CM' 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 (nmg *nmg_CM) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(nmg.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, nmg.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(nmg.minus) - 1; j >= 0; j-- { + b = append(b, nmg.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + for j := len(nmg.percent) - 1; j >= 0; j-- { + b = append(b, nmg.percent[j]) + } + + return b +} @@ -119,3 +119,40 @@ func (nn *nn) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'nn' 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 (nn *nn) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(nn.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, nn.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(nn.minus) - 1; j >= 0; j-- { + b = append(b, nn.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, nn.Percent[0]) + + return b +} diff --git a/nn_NO/nn_NO.go b/nn_NO/nn_NO.go index d322aac2..e09c683a 100644 --- a/nn_NO/nn_NO.go +++ b/nn_NO/nn_NO.go @@ -119,3 +119,40 @@ func (nn *nn_NO) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'nn_NO' 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 (nn *nn_NO) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(nn.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, nn.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(nn.minus) - 1; j >= 0; j-- { + b = append(b, nn.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, nn.Percent[0]) + + return b +} @@ -116,3 +116,13 @@ func (nnh *nnh) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'nnh' 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 (nnh *nnh) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + return []byte(s) +} diff --git a/nnh_CM/nnh_CM.go b/nnh_CM/nnh_CM.go index 498c8caf..7cc098e9 100644 --- a/nnh_CM/nnh_CM.go +++ b/nnh_CM/nnh_CM.go @@ -116,3 +116,13 @@ func (nnh *nnh_CM) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'nnh_CM' 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 (nnh *nnh_CM) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + return []byte(s) +} @@ -109,3 +109,42 @@ func (nus *nus) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'nus' 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 (nus *nus) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(nus.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, nus.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(nus.minus) - 1; j >= 0; j-- { + b = append(b, nus.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + for j := len(nus.percent) - 1; j >= 0; j-- { + b = append(b, nus.percent[j]) + } + + return b +} diff --git a/nus_SS/nus_SS.go b/nus_SS/nus_SS.go index 5b803122..edfade3f 100644 --- a/nus_SS/nus_SS.go +++ b/nus_SS/nus_SS.go @@ -109,3 +109,42 @@ func (nus *nus_SS) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'nus_SS' 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 (nus *nus_SS) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(nus.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, nus.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(nus.minus) - 1; j >= 0; j-- { + b = append(b, nus.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + for j := len(nus.percent) - 1; j >= 0; j-- { + b = append(b, nus.percent[j]) + } + + return b +} @@ -79,3 +79,13 @@ func (nyn *nyn) 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 'nyn' 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 (nyn *nyn) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + return []byte(s) +} diff --git a/nyn_UG/nyn_UG.go b/nyn_UG/nyn_UG.go index 7f9a79ba..51b0f6d9 100644 --- a/nyn_UG/nyn_UG.go +++ b/nyn_UG/nyn_UG.go @@ -79,3 +79,13 @@ func (nyn *nyn_UG) 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 'nyn_UG' 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 (nyn *nyn_UG) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + return []byte(s) +} @@ -79,3 +79,13 @@ func (om *om) 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 'om' 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 (om *om) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + return []byte(s) +} diff --git a/om_ET/om_ET.go b/om_ET/om_ET.go index d9d44076..86629421 100644 --- a/om_ET/om_ET.go +++ b/om_ET/om_ET.go @@ -79,3 +79,13 @@ func (om *om_ET) 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 'om_ET' 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 (om *om_ET) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + return []byte(s) +} diff --git a/om_KE/om_KE.go b/om_KE/om_KE.go index decf99b5..aa023784 100644 --- a/om_KE/om_KE.go +++ b/om_KE/om_KE.go @@ -79,3 +79,13 @@ func (om *om_KE) 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 'om_KE' 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 (om *om_KE) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + return []byte(s) +} @@ -125,3 +125,42 @@ func (or *or) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'or' 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 (or *or) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(or.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, or.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(or.minus) - 1; j >= 0; j-- { + b = append(b, or.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + for j := len(or.percent) - 1; j >= 0; j-- { + b = append(b, or.percent[j]) + } + + return b +} diff --git a/or_IN/or_IN.go b/or_IN/or_IN.go index 5c72c374..b712922a 100644 --- a/or_IN/or_IN.go +++ b/or_IN/or_IN.go @@ -125,3 +125,42 @@ func (or *or_IN) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'or_IN' 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 (or *or_IN) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(or.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, or.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(or.minus) - 1; j >= 0; j-- { + b = append(b, or.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + for j := len(or.percent) - 1; j >= 0; j-- { + b = append(b, or.percent[j]) + } + + return b +} @@ -117,3 +117,38 @@ func (os *os) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'os' 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 (os *os) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(os.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, os.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, os.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, os.Percent[0]) + + return b +} diff --git a/os_GE/os_GE.go b/os_GE/os_GE.go index 72479d6a..30d4e6fa 100644 --- a/os_GE/os_GE.go +++ b/os_GE/os_GE.go @@ -117,3 +117,38 @@ func (os *os_GE) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'os_GE' 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 (os *os_GE) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(os.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, os.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, os.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, os.Percent[0]) + + return b +} diff --git a/os_RU/os_RU.go b/os_RU/os_RU.go index c990e6b9..c1d191d1 100644 --- a/os_RU/os_RU.go +++ b/os_RU/os_RU.go @@ -117,3 +117,38 @@ func (os *os_RU) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'os_RU' 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 (os *os_RU) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(os.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, os.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, os.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, os.Percent[0]) + + return b +} @@ -137,3 +137,43 @@ func (pa *pa) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'pa' 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 (pa *pa) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(pa.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + for j := len(pa.decimal) - 1; j >= 0; j-- { + b = append(b, pa.decimal[j]) + } + + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, pa.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + for j := len(pa.percent) - 1; j >= 0; j-- { + b = append(b, pa.percent[j]) + } + + return b +} diff --git a/pa_Arab/pa_Arab.go b/pa_Arab/pa_Arab.go index b4df7dc2..d6f48384 100644 --- a/pa_Arab/pa_Arab.go +++ b/pa_Arab/pa_Arab.go @@ -139,3 +139,45 @@ func (pa *pa_Arab) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'pa_Arab' 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 (pa *pa_Arab) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(pa.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + for j := len(pa.decimal) - 1; j >= 0; j-- { + b = append(b, pa.decimal[j]) + } + + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(pa.minus) - 1; j >= 0; j-- { + b = append(b, pa.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + for j := len(pa.percent) - 1; j >= 0; j-- { + b = append(b, pa.percent[j]) + } + + return b +} diff --git a/pa_Arab_PK/pa_Arab_PK.go b/pa_Arab_PK/pa_Arab_PK.go index 1b112484..9e0a6464 100644 --- a/pa_Arab_PK/pa_Arab_PK.go +++ b/pa_Arab_PK/pa_Arab_PK.go @@ -137,3 +137,43 @@ func (pa *pa_Arab_PK) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'pa_Arab_PK' 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 (pa *pa_Arab_PK) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(pa.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + for j := len(pa.decimal) - 1; j >= 0; j-- { + b = append(b, pa.decimal[j]) + } + + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, pa.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + for j := len(pa.percent) - 1; j >= 0; j-- { + b = append(b, pa.percent[j]) + } + + return b +} diff --git a/pa_Guru/pa_Guru.go b/pa_Guru/pa_Guru.go index bed7dd00..0fc3fd6d 100644 --- a/pa_Guru/pa_Guru.go +++ b/pa_Guru/pa_Guru.go @@ -137,3 +137,43 @@ func (pa *pa_Guru) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'pa_Guru' 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 (pa *pa_Guru) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(pa.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + for j := len(pa.decimal) - 1; j >= 0; j-- { + b = append(b, pa.decimal[j]) + } + + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, pa.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + for j := len(pa.percent) - 1; j >= 0; j-- { + b = append(b, pa.percent[j]) + } + + return b +} diff --git a/pa_Guru_IN/pa_Guru_IN.go b/pa_Guru_IN/pa_Guru_IN.go index c6d654c2..93d32198 100644 --- a/pa_Guru_IN/pa_Guru_IN.go +++ b/pa_Guru_IN/pa_Guru_IN.go @@ -137,3 +137,43 @@ func (pa *pa_Guru_IN) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'pa_Guru_IN' 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 (pa *pa_Guru_IN) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(pa.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + for j := len(pa.decimal) - 1; j >= 0; j-- { + b = append(b, pa.decimal[j]) + } + + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, pa.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + for j := len(pa.percent) - 1; j >= 0; j-- { + b = append(b, pa.percent[j]) + } + + return b +} @@ -157,3 +157,38 @@ func (pl *pl) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'pl' 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 (pl *pl) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(pl.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, pl.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, pl.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, pl.Percent[0]) + + return b +} diff --git a/pl_PL/pl_PL.go b/pl_PL/pl_PL.go index 12856732..33356732 100644 --- a/pl_PL/pl_PL.go +++ b/pl_PL/pl_PL.go @@ -157,3 +157,38 @@ func (pl *pl_PL) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'pl_PL' 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 (pl *pl_PL) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(pl.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, pl.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, pl.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, pl.Percent[0]) + + return b +} @@ -124,3 +124,38 @@ func (prg *prg) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'prg' 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 (prg *prg) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(prg.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, prg.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, prg.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, prg.Percent[0]) + + return b +} diff --git a/prg_001/prg_001.go b/prg_001/prg_001.go index 5f92be53..75c28ce6 100644 --- a/prg_001/prg_001.go +++ b/prg_001/prg_001.go @@ -124,3 +124,38 @@ func (prg *prg_001) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'prg_001' 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 (prg *prg_001) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(prg.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, prg.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, prg.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, prg.Percent[0]) + + return b +} @@ -79,3 +79,13 @@ func (ps *ps) 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 'ps' 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 (ps *ps) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + return []byte(s) +} diff --git a/ps_AF/ps_AF.go b/ps_AF/ps_AF.go index dc7c0346..08dbf1de 100644 --- a/ps_AF/ps_AF.go +++ b/ps_AF/ps_AF.go @@ -79,3 +79,13 @@ func (ps *ps_AF) 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 'ps_AF' 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 (ps *ps_AF) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + return []byte(s) +} @@ -125,3 +125,38 @@ func (pt *pt) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'pt' 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 (pt *pt) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(pt.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, pt.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, pt.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, pt.Percent[0]) + + return b +} diff --git a/pt_AO/pt_AO.go b/pt_AO/pt_AO.go index 06fc6719..81d8a8ff 100644 --- a/pt_AO/pt_AO.go +++ b/pt_AO/pt_AO.go @@ -125,3 +125,38 @@ func (pt *pt_AO) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'pt_AO' 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 (pt *pt_AO) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(pt.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, pt.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, pt.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, pt.Percent[0]) + + return b +} diff --git a/pt_BR/pt_BR.go b/pt_BR/pt_BR.go index 79469ff9..6b308948 100644 --- a/pt_BR/pt_BR.go +++ b/pt_BR/pt_BR.go @@ -125,3 +125,38 @@ func (pt *pt_BR) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'pt_BR' 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 (pt *pt_BR) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(pt.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, pt.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, pt.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, pt.Percent[0]) + + return b +} diff --git a/pt_CH/pt_CH.go b/pt_CH/pt_CH.go index d03bfcdf..6a924dc9 100644 --- a/pt_CH/pt_CH.go +++ b/pt_CH/pt_CH.go @@ -125,3 +125,38 @@ func (pt *pt_CH) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'pt_CH' 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 (pt *pt_CH) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(pt.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, pt.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, pt.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, pt.Percent[0]) + + return b +} diff --git a/pt_CV/pt_CV.go b/pt_CV/pt_CV.go index 125b5a67..16c5f6cd 100644 --- a/pt_CV/pt_CV.go +++ b/pt_CV/pt_CV.go @@ -125,3 +125,38 @@ func (pt *pt_CV) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'pt_CV' 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 (pt *pt_CV) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(pt.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, pt.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, pt.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, pt.Percent[0]) + + return b +} diff --git a/pt_GQ/pt_GQ.go b/pt_GQ/pt_GQ.go index d974217b..90adfb47 100644 --- a/pt_GQ/pt_GQ.go +++ b/pt_GQ/pt_GQ.go @@ -125,3 +125,38 @@ func (pt *pt_GQ) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'pt_GQ' 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 (pt *pt_GQ) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(pt.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, pt.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, pt.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, pt.Percent[0]) + + return b +} diff --git a/pt_GW/pt_GW.go b/pt_GW/pt_GW.go index 408112ff..3c719ea8 100644 --- a/pt_GW/pt_GW.go +++ b/pt_GW/pt_GW.go @@ -125,3 +125,38 @@ func (pt *pt_GW) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'pt_GW' 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 (pt *pt_GW) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(pt.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, pt.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, pt.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, pt.Percent[0]) + + return b +} diff --git a/pt_LU/pt_LU.go b/pt_LU/pt_LU.go index 8cd25e55..a65db99b 100644 --- a/pt_LU/pt_LU.go +++ b/pt_LU/pt_LU.go @@ -125,3 +125,38 @@ func (pt *pt_LU) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'pt_LU' 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 (pt *pt_LU) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(pt.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, pt.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, pt.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, pt.Percent[0]) + + return b +} diff --git a/pt_MO/pt_MO.go b/pt_MO/pt_MO.go index 26748241..f87618d1 100644 --- a/pt_MO/pt_MO.go +++ b/pt_MO/pt_MO.go @@ -125,3 +125,38 @@ func (pt *pt_MO) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'pt_MO' 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 (pt *pt_MO) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(pt.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, pt.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, pt.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, pt.Percent[0]) + + return b +} diff --git a/pt_MZ/pt_MZ.go b/pt_MZ/pt_MZ.go index 80fc87d2..5821e2c4 100644 --- a/pt_MZ/pt_MZ.go +++ b/pt_MZ/pt_MZ.go @@ -125,3 +125,38 @@ func (pt *pt_MZ) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'pt_MZ' 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 (pt *pt_MZ) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(pt.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, pt.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, pt.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, pt.Percent[0]) + + return b +} diff --git a/pt_PT/pt_PT.go b/pt_PT/pt_PT.go index 8833d6f9..3eb51bb7 100644 --- a/pt_PT/pt_PT.go +++ b/pt_PT/pt_PT.go @@ -128,3 +128,38 @@ func (pt *pt_PT) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'pt_PT' 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 (pt *pt_PT) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(pt.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, pt.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, pt.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, pt.Percent[0]) + + return b +} diff --git a/pt_ST/pt_ST.go b/pt_ST/pt_ST.go index 54a67262..5ebf8e2d 100644 --- a/pt_ST/pt_ST.go +++ b/pt_ST/pt_ST.go @@ -125,3 +125,38 @@ func (pt *pt_ST) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'pt_ST' 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 (pt *pt_ST) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(pt.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, pt.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, pt.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, pt.Percent[0]) + + return b +} diff --git a/pt_TL/pt_TL.go b/pt_TL/pt_TL.go index 04312776..765a3c97 100644 --- a/pt_TL/pt_TL.go +++ b/pt_TL/pt_TL.go @@ -125,3 +125,38 @@ func (pt *pt_TL) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'pt_TL' 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 (pt *pt_TL) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(pt.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, pt.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, pt.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, pt.Percent[0]) + + return b +} @@ -107,3 +107,38 @@ func (qu *qu) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'qu' 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 (qu *qu) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(qu.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, qu.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, qu.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, qu.Percent[0]) + + return b +} diff --git a/qu_BO/qu_BO.go b/qu_BO/qu_BO.go index d5396510..e1d3d50c 100644 --- a/qu_BO/qu_BO.go +++ b/qu_BO/qu_BO.go @@ -107,3 +107,38 @@ func (qu *qu_BO) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'qu_BO' 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 (qu *qu_BO) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(qu.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, qu.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, qu.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, qu.Percent[0]) + + return b +} diff --git a/qu_EC/qu_EC.go b/qu_EC/qu_EC.go index 3f016e8f..79e32a77 100644 --- a/qu_EC/qu_EC.go +++ b/qu_EC/qu_EC.go @@ -107,3 +107,38 @@ func (qu *qu_EC) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'qu_EC' 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 (qu *qu_EC) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(qu.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, qu.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, qu.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, qu.Percent[0]) + + return b +} diff --git a/qu_PE/qu_PE.go b/qu_PE/qu_PE.go index 48ce4aa9..50be5182 100644 --- a/qu_PE/qu_PE.go +++ b/qu_PE/qu_PE.go @@ -107,3 +107,38 @@ func (qu *qu_PE) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'qu_PE' 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 (qu *qu_PE) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(qu.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, qu.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, qu.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, qu.Percent[0]) + + return b +} @@ -119,3 +119,40 @@ func (rm *rm) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'rm' 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 (rm *rm) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(rm.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, rm.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(rm.minus) - 1; j >= 0; j-- { + b = append(b, rm.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, rm.Percent[0]) + + return b +} diff --git a/rm_CH/rm_CH.go b/rm_CH/rm_CH.go index a8fbfb0b..bd369b30 100644 --- a/rm_CH/rm_CH.go +++ b/rm_CH/rm_CH.go @@ -119,3 +119,40 @@ func (rm *rm_CH) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'rm_CH' 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 (rm *rm_CH) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(rm.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, rm.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(rm.minus) - 1; j >= 0; j-- { + b = append(b, rm.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, rm.Percent[0]) + + return b +} @@ -109,3 +109,42 @@ func (rn *rn) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'rn' 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 (rn *rn) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(rn.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, rn.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(rn.minus) - 1; j >= 0; j-- { + b = append(b, rn.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + for j := len(rn.percent) - 1; j >= 0; j-- { + b = append(b, rn.percent[j]) + } + + return b +} diff --git a/rn_BI/rn_BI.go b/rn_BI/rn_BI.go index bfc88028..eaf1e8c0 100644 --- a/rn_BI/rn_BI.go +++ b/rn_BI/rn_BI.go @@ -109,3 +109,42 @@ func (rn *rn_BI) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'rn_BI' 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 (rn *rn_BI) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(rn.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, rn.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(rn.minus) - 1; j >= 0; j-- { + b = append(b, rn.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + for j := len(rn.percent) - 1; j >= 0; j-- { + b = append(b, rn.percent[j]) + } + + return b +} @@ -144,3 +144,38 @@ func (ro *ro) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'ro' 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 (ro *ro) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(ro.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, ro.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, ro.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, ro.Percent[0]) + + return b +} diff --git a/ro_MD/ro_MD.go b/ro_MD/ro_MD.go index 7a7186a2..9e0a881f 100644 --- a/ro_MD/ro_MD.go +++ b/ro_MD/ro_MD.go @@ -144,3 +144,38 @@ func (ro *ro_MD) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'ro_MD' 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 (ro *ro_MD) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(ro.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, ro.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, ro.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, ro.Percent[0]) + + return b +} diff --git a/ro_RO/ro_RO.go b/ro_RO/ro_RO.go index 2ab0f49c..038a9018 100644 --- a/ro_RO/ro_RO.go +++ b/ro_RO/ro_RO.go @@ -144,3 +144,38 @@ func (ro *ro_RO) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'ro_RO' 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 (ro *ro_RO) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(ro.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, ro.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, ro.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, ro.Percent[0]) + + return b +} @@ -79,3 +79,13 @@ func (rof *rof) 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 'rof' 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 (rof *rof) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + return []byte(s) +} diff --git a/rof_TZ/rof_TZ.go b/rof_TZ/rof_TZ.go index 31d84c99..23fe2699 100644 --- a/rof_TZ/rof_TZ.go +++ b/rof_TZ/rof_TZ.go @@ -79,3 +79,13 @@ func (rof *rof_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 'rof_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 (rof *rof_TZ) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + return []byte(s) +} diff --git a/root/root.go b/root/root.go index 0617af29..e9215320 100644 --- a/root/root.go +++ b/root/root.go @@ -72,3 +72,13 @@ func (root *root) 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 'root' 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 (root *root) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + return []byte(s) +} @@ -161,3 +161,38 @@ func (ru *ru) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'ru' 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 (ru *ru) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(ru.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, ru.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, ru.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, ru.Percent[0]) + + return b +} diff --git a/ru_BY/ru_BY.go b/ru_BY/ru_BY.go index 8b24bb87..180870ec 100644 --- a/ru_BY/ru_BY.go +++ b/ru_BY/ru_BY.go @@ -161,3 +161,38 @@ func (ru *ru_BY) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'ru_BY' 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 (ru *ru_BY) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(ru.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, ru.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, ru.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, ru.Percent[0]) + + return b +} diff --git a/ru_KG/ru_KG.go b/ru_KG/ru_KG.go index cd14411d..0ceacdfb 100644 --- a/ru_KG/ru_KG.go +++ b/ru_KG/ru_KG.go @@ -161,3 +161,38 @@ func (ru *ru_KG) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'ru_KG' 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 (ru *ru_KG) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(ru.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, ru.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, ru.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, ru.Percent[0]) + + return b +} diff --git a/ru_KZ/ru_KZ.go b/ru_KZ/ru_KZ.go index 341b53dc..b4305e30 100644 --- a/ru_KZ/ru_KZ.go +++ b/ru_KZ/ru_KZ.go @@ -54,8 +54,8 @@ func (ru *ru_KZ) CardinalPluralRule(num float64, v uint64) locales.PluralRule { n := math.Abs(num) i := int64(n) - iMod100 := i % 100 iMod10 := i % 10 + iMod100 := i % 100 if v == 0 && iMod10 == 1 && iMod100 != 11 { return locales.PluralRuleOne @@ -161,3 +161,38 @@ func (ru *ru_KZ) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'ru_KZ' 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 (ru *ru_KZ) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(ru.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, ru.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, ru.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, ru.Percent[0]) + + return b +} diff --git a/ru_MD/ru_MD.go b/ru_MD/ru_MD.go index b10a378d..605a3ec2 100644 --- a/ru_MD/ru_MD.go +++ b/ru_MD/ru_MD.go @@ -161,3 +161,38 @@ func (ru *ru_MD) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'ru_MD' 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 (ru *ru_MD) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(ru.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, ru.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, ru.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, ru.Percent[0]) + + return b +} diff --git a/ru_RU/ru_RU.go b/ru_RU/ru_RU.go index 6ec4147c..fa5da9aa 100644 --- a/ru_RU/ru_RU.go +++ b/ru_RU/ru_RU.go @@ -54,8 +54,8 @@ func (ru *ru_RU) CardinalPluralRule(num float64, v uint64) locales.PluralRule { n := math.Abs(num) i := int64(n) - iMod10 := i % 10 iMod100 := i % 100 + iMod10 := i % 10 if v == 0 && iMod10 == 1 && iMod100 != 11 { return locales.PluralRuleOne @@ -161,3 +161,38 @@ func (ru *ru_RU) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'ru_RU' 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 (ru *ru_RU) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(ru.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, ru.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, ru.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, ru.Percent[0]) + + return b +} diff --git a/ru_UA/ru_UA.go b/ru_UA/ru_UA.go index 35c6decb..713fe1e5 100644 --- a/ru_UA/ru_UA.go +++ b/ru_UA/ru_UA.go @@ -161,3 +161,38 @@ func (ru *ru_UA) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'ru_UA' 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 (ru *ru_UA) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(ru.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, ru.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, ru.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, ru.Percent[0]) + + return b +} @@ -61,6 +61,12 @@ type Translator interface { // returned as a []byte just in case the caller wishes to add more and can help // avoid allocations; otherwise just cast as string. FmtNumber(num float64, v uint64) []byte + + // returns 'num' with digits/precision of 'v' for '{{ .Locale }}' 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 + FmtPercent(num float64, v uint64) []byte } // String returns the string value of PluralRule @@ -72,3 +72,13 @@ func (rw *rw) 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 'rw' 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 (rw *rw) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + return []byte(s) +} diff --git a/rw_RW/rw_RW.go b/rw_RW/rw_RW.go index 54b1b4c5..d32851bd 100644 --- a/rw_RW/rw_RW.go +++ b/rw_RW/rw_RW.go @@ -72,3 +72,13 @@ func (rw *rw_RW) 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 'rw_RW' 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 (rw *rw_RW) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + return []byte(s) +} @@ -79,3 +79,13 @@ func (rwk *rwk) 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 'rwk' 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 (rwk *rwk) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + return []byte(s) +} diff --git a/rwk_TZ/rwk_TZ.go b/rwk_TZ/rwk_TZ.go index 3b3be58c..005b065d 100644 --- a/rwk_TZ/rwk_TZ.go +++ b/rwk_TZ/rwk_TZ.go @@ -79,3 +79,13 @@ func (rwk *rwk_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 'rwk_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 (rwk *rwk_TZ) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + return []byte(s) +} @@ -72,3 +72,13 @@ func (sah *sah) 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 'sah' 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 (sah *sah) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + return []byte(s) +} diff --git a/sah_RU/sah_RU.go b/sah_RU/sah_RU.go index 8218a7cc..dfbed82a 100644 --- a/sah_RU/sah_RU.go +++ b/sah_RU/sah_RU.go @@ -72,3 +72,13 @@ func (sah *sah_RU) 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 'sah_RU' 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 (sah *sah_RU) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + return []byte(s) +} @@ -79,3 +79,13 @@ func (saq *saq) 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 'saq' 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 (saq *saq) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + return []byte(s) +} diff --git a/saq_KE/saq_KE.go b/saq_KE/saq_KE.go index 471c7e00..b55b0c1c 100644 --- a/saq_KE/saq_KE.go +++ b/saq_KE/saq_KE.go @@ -79,3 +79,13 @@ func (saq *saq_KE) 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 'saq_KE' 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 (saq *saq_KE) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + return []byte(s) +} @@ -109,3 +109,42 @@ func (sbp *sbp) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'sbp' 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 (sbp *sbp) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(sbp.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, sbp.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(sbp.minus) - 1; j >= 0; j-- { + b = append(b, sbp.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + for j := len(sbp.percent) - 1; j >= 0; j-- { + b = append(b, sbp.percent[j]) + } + + return b +} diff --git a/sbp_TZ/sbp_TZ.go b/sbp_TZ/sbp_TZ.go index 0a5c70c9..38b8a72b 100644 --- a/sbp_TZ/sbp_TZ.go +++ b/sbp_TZ/sbp_TZ.go @@ -109,3 +109,42 @@ func (sbp *sbp_TZ) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'sbp_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 (sbp *sbp_TZ) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(sbp.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, sbp.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(sbp.minus) - 1; j >= 0; j-- { + b = append(b, sbp.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + for j := len(sbp.percent) - 1; j >= 0; j-- { + b = append(b, sbp.percent[j]) + } + + return b +} @@ -121,3 +121,40 @@ func (se *se) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'se' 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 (se *se) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(se.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, se.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(se.minus) - 1; j >= 0; j-- { + b = append(b, se.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, se.Percent[0]) + + return b +} diff --git a/se_FI/se_FI.go b/se_FI/se_FI.go index 9089569c..d0df1936 100644 --- a/se_FI/se_FI.go +++ b/se_FI/se_FI.go @@ -121,3 +121,40 @@ func (se *se_FI) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'se_FI' 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 (se *se_FI) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(se.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, se.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(se.minus) - 1; j >= 0; j-- { + b = append(b, se.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, se.Percent[0]) + + return b +} diff --git a/se_NO/se_NO.go b/se_NO/se_NO.go index 2e197dc2..1e6f9597 100644 --- a/se_NO/se_NO.go +++ b/se_NO/se_NO.go @@ -121,3 +121,40 @@ func (se *se_NO) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'se_NO' 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 (se *se_NO) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(se.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, se.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(se.minus) - 1; j >= 0; j-- { + b = append(b, se.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, se.Percent[0]) + + return b +} diff --git a/se_SE/se_SE.go b/se_SE/se_SE.go index 2516b1d2..20f6dc50 100644 --- a/se_SE/se_SE.go +++ b/se_SE/se_SE.go @@ -121,3 +121,40 @@ func (se *se_SE) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'se_SE' 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 (se *se_SE) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(se.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, se.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(se.minus) - 1; j >= 0; j-- { + b = append(b, se.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, se.Percent[0]) + + return b +} @@ -79,3 +79,13 @@ func (seh *seh) 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 'seh' 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 (seh *seh) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + return []byte(s) +} diff --git a/seh_MZ/seh_MZ.go b/seh_MZ/seh_MZ.go index e6274879..88b6f464 100644 --- a/seh_MZ/seh_MZ.go +++ b/seh_MZ/seh_MZ.go @@ -79,3 +79,13 @@ func (seh *seh_MZ) 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 'seh_MZ' 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 (seh *seh_MZ) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + return []byte(s) +} @@ -72,3 +72,13 @@ func (ses *ses) 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 'ses' 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 (ses *ses) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + return []byte(s) +} diff --git a/ses_ML/ses_ML.go b/ses_ML/ses_ML.go index 86f5dffb..3f383277 100644 --- a/ses_ML/ses_ML.go +++ b/ses_ML/ses_ML.go @@ -72,3 +72,13 @@ func (ses *ses_ML) 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 'ses_ML' 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 (ses *ses_ML) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + return []byte(s) +} @@ -72,3 +72,13 @@ func (sg *sg) 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 'sg' 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 (sg *sg) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + return []byte(s) +} diff --git a/sg_CF/sg_CF.go b/sg_CF/sg_CF.go index bb1d05e1..a1a5b9d1 100644 --- a/sg_CF/sg_CF.go +++ b/sg_CF/sg_CF.go @@ -72,3 +72,13 @@ func (sg *sg_CF) 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 'sg_CF' 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 (sg *sg_CF) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + return []byte(s) +} @@ -82,3 +82,13 @@ func (shi *shi) 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 'shi' 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 (shi *shi) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + return []byte(s) +} diff --git a/shi_Latn/shi_Latn.go b/shi_Latn/shi_Latn.go index 65d89e8a..17da44e9 100644 --- a/shi_Latn/shi_Latn.go +++ b/shi_Latn/shi_Latn.go @@ -82,3 +82,13 @@ func (shi *shi_Latn) 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 'shi_Latn' 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 (shi *shi_Latn) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + return []byte(s) +} diff --git a/shi_Latn_MA/shi_Latn_MA.go b/shi_Latn_MA/shi_Latn_MA.go index d7343187..a52fe1bf 100644 --- a/shi_Latn_MA/shi_Latn_MA.go +++ b/shi_Latn_MA/shi_Latn_MA.go @@ -82,3 +82,13 @@ func (shi *shi_Latn_MA) 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 'shi_Latn_MA' 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 (shi *shi_Latn_MA) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + return []byte(s) +} diff --git a/shi_Tfng/shi_Tfng.go b/shi_Tfng/shi_Tfng.go index ed413132..d8e048f0 100644 --- a/shi_Tfng/shi_Tfng.go +++ b/shi_Tfng/shi_Tfng.go @@ -82,3 +82,13 @@ func (shi *shi_Tfng) 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 'shi_Tfng' 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 (shi *shi_Tfng) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + return []byte(s) +} diff --git a/shi_Tfng_MA/shi_Tfng_MA.go b/shi_Tfng_MA/shi_Tfng_MA.go index 18cc61ae..097a580e 100644 --- a/shi_Tfng_MA/shi_Tfng_MA.go +++ b/shi_Tfng_MA/shi_Tfng_MA.go @@ -82,3 +82,13 @@ func (shi *shi_Tfng_MA) 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 'shi_Tfng_MA' 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 (shi *shi_Tfng_MA) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + return []byte(s) +} @@ -129,3 +129,38 @@ func (si *si) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'si' 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 (si *si) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(si.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, si.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, si.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, si.Percent[0]) + + return b +} diff --git a/si_LK/si_LK.go b/si_LK/si_LK.go index e38fa808..ef5de4a7 100644 --- a/si_LK/si_LK.go +++ b/si_LK/si_LK.go @@ -129,3 +129,38 @@ func (si *si_LK) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'si_LK' 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 (si *si_LK) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(si.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, si.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, si.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, si.Percent[0]) + + return b +} @@ -155,3 +155,38 @@ func (sk *sk) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'sk' 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 (sk *sk) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(sk.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, sk.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, sk.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, sk.Percent[0]) + + return b +} diff --git a/sk_SK/sk_SK.go b/sk_SK/sk_SK.go index 4c535b11..12305cd8 100644 --- a/sk_SK/sk_SK.go +++ b/sk_SK/sk_SK.go @@ -155,3 +155,38 @@ func (sk *sk_SK) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'sk_SK' 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 (sk *sk_SK) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(sk.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, sk.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, sk.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, sk.Percent[0]) + + return b +} @@ -157,3 +157,38 @@ func (sl *sl) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'sl' 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 (sl *sl) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(sl.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, sl.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, sl.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, sl.Percent[0]) + + return b +} diff --git a/sl_SI/sl_SI.go b/sl_SI/sl_SI.go index 49658439..4b957fa1 100644 --- a/sl_SI/sl_SI.go +++ b/sl_SI/sl_SI.go @@ -157,3 +157,38 @@ func (sl *sl_SI) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'sl_SI' 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 (sl *sl_SI) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(sl.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, sl.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, sl.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, sl.Percent[0]) + + return b +} @@ -81,3 +81,13 @@ func (smn *smn) 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 'smn' 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 (smn *smn) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + return []byte(s) +} diff --git a/smn_FI/smn_FI.go b/smn_FI/smn_FI.go index 383f44b9..74edec7f 100644 --- a/smn_FI/smn_FI.go +++ b/smn_FI/smn_FI.go @@ -81,3 +81,13 @@ func (smn *smn_FI) 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 'smn_FI' 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 (smn *smn_FI) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + return []byte(s) +} @@ -79,3 +79,13 @@ func (sn *sn) 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 'sn' 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 (sn *sn) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + return []byte(s) +} diff --git a/sn_ZW/sn_ZW.go b/sn_ZW/sn_ZW.go index 6a348c65..5daccf06 100644 --- a/sn_ZW/sn_ZW.go +++ b/sn_ZW/sn_ZW.go @@ -79,3 +79,13 @@ func (sn *sn_ZW) 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 'sn_ZW' 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 (sn *sn_ZW) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + return []byte(s) +} @@ -79,3 +79,13 @@ func (so *so) 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 'so' 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 (so *so) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + return []byte(s) +} diff --git a/so_DJ/so_DJ.go b/so_DJ/so_DJ.go index ceb2b23d..8b65fc0f 100644 --- a/so_DJ/so_DJ.go +++ b/so_DJ/so_DJ.go @@ -79,3 +79,13 @@ func (so *so_DJ) 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 'so_DJ' 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 (so *so_DJ) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + return []byte(s) +} diff --git a/so_ET/so_ET.go b/so_ET/so_ET.go index ee87b01a..3f4bd55b 100644 --- a/so_ET/so_ET.go +++ b/so_ET/so_ET.go @@ -79,3 +79,13 @@ func (so *so_ET) 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 'so_ET' 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 (so *so_ET) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + return []byte(s) +} diff --git a/so_KE/so_KE.go b/so_KE/so_KE.go index 1f14d3e4..f1ead3da 100644 --- a/so_KE/so_KE.go +++ b/so_KE/so_KE.go @@ -79,3 +79,13 @@ func (so *so_KE) 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 'so_KE' 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 (so *so_KE) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + return []byte(s) +} diff --git a/so_SO/so_SO.go b/so_SO/so_SO.go index 6af55a3a..7a82dbb7 100644 --- a/so_SO/so_SO.go +++ b/so_SO/so_SO.go @@ -79,3 +79,13 @@ func (so *so_SO) 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 'so_SO' 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 (so *so_SO) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + return []byte(s) +} @@ -65,8 +65,8 @@ func (sq *sq) CardinalPluralRule(num float64, v uint64) locales.PluralRule { func (sq *sq) OrdinalPluralRule(num float64, v uint64) locales.PluralRule { n := math.Abs(num) - nMod10 := math.Mod(n, 10) nMod100 := math.Mod(n, 100) + nMod10 := math.Mod(n, 10) if n == 1 { return locales.PluralRuleOne @@ -139,3 +139,38 @@ func (sq *sq) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'sq' 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 (sq *sq) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(sq.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, sq.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, sq.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, sq.Percent[0]) + + return b +} diff --git a/sq_AL/sq_AL.go b/sq_AL/sq_AL.go index 23c0054e..a921c3eb 100644 --- a/sq_AL/sq_AL.go +++ b/sq_AL/sq_AL.go @@ -139,3 +139,38 @@ func (sq *sq_AL) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'sq_AL' 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 (sq *sq_AL) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(sq.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, sq.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, sq.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, sq.Percent[0]) + + return b +} diff --git a/sq_MK/sq_MK.go b/sq_MK/sq_MK.go index 0ebabc1f..cb4fe918 100644 --- a/sq_MK/sq_MK.go +++ b/sq_MK/sq_MK.go @@ -65,8 +65,8 @@ func (sq *sq_MK) CardinalPluralRule(num float64, v uint64) locales.PluralRule { func (sq *sq_MK) OrdinalPluralRule(num float64, v uint64) locales.PluralRule { n := math.Abs(num) - nMod10 := math.Mod(n, 10) nMod100 := math.Mod(n, 100) + nMod10 := math.Mod(n, 10) if n == 1 { return locales.PluralRuleOne @@ -139,3 +139,38 @@ func (sq *sq_MK) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'sq_MK' 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 (sq *sq_MK) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(sq.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, sq.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, sq.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, sq.Percent[0]) + + return b +} diff --git a/sq_XK/sq_XK.go b/sq_XK/sq_XK.go index 0d7c39be..95c55c31 100644 --- a/sq_XK/sq_XK.go +++ b/sq_XK/sq_XK.go @@ -139,3 +139,38 @@ func (sq *sq_XK) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'sq_XK' 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 (sq *sq_XK) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(sq.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, sq.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, sq.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, sq.Percent[0]) + + return b +} @@ -57,8 +57,8 @@ func (sr *sr) CardinalPluralRule(num float64, v uint64) locales.PluralRule { f := locales.F(n, v) iMod10 := i % 10 iMod100 := i % 100 - fMod10 := f % 10 fMod100 := f % 100 + fMod10 := f % 10 if (v == 0 && iMod10 == 1 && iMod100 != 11) || (fMod10 == 1 && fMod100 != 11) { return locales.PluralRuleOne @@ -145,3 +145,38 @@ func (sr *sr) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'sr' 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 (sr *sr) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(sr.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, sr.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, sr.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, sr.Percent[0]) + + return b +} diff --git a/sr_Cyrl/sr_Cyrl.go b/sr_Cyrl/sr_Cyrl.go index 3cc8881a..2d11673c 100644 --- a/sr_Cyrl/sr_Cyrl.go +++ b/sr_Cyrl/sr_Cyrl.go @@ -55,8 +55,8 @@ func (sr *sr_Cyrl) CardinalPluralRule(num float64, v uint64) locales.PluralRule n := math.Abs(num) i := int64(n) f := locales.F(n, v) - iMod100 := i % 100 iMod10 := i % 10 + iMod100 := i % 100 fMod10 := f % 10 fMod100 := f % 100 @@ -145,3 +145,38 @@ func (sr *sr_Cyrl) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'sr_Cyrl' 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 (sr *sr_Cyrl) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(sr.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, sr.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, sr.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, sr.Percent[0]) + + return b +} diff --git a/sr_Cyrl_BA/sr_Cyrl_BA.go b/sr_Cyrl_BA/sr_Cyrl_BA.go index 49478d8c..23026b0f 100644 --- a/sr_Cyrl_BA/sr_Cyrl_BA.go +++ b/sr_Cyrl_BA/sr_Cyrl_BA.go @@ -145,3 +145,38 @@ func (sr *sr_Cyrl_BA) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'sr_Cyrl_BA' 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 (sr *sr_Cyrl_BA) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(sr.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, sr.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, sr.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, sr.Percent[0]) + + return b +} diff --git a/sr_Cyrl_ME/sr_Cyrl_ME.go b/sr_Cyrl_ME/sr_Cyrl_ME.go index 996b0a66..29cdeeec 100644 --- a/sr_Cyrl_ME/sr_Cyrl_ME.go +++ b/sr_Cyrl_ME/sr_Cyrl_ME.go @@ -57,8 +57,8 @@ func (sr *sr_Cyrl_ME) CardinalPluralRule(num float64, v uint64) locales.PluralRu f := locales.F(n, v) iMod10 := i % 10 iMod100 := i % 100 - fMod10 := f % 10 fMod100 := f % 100 + fMod10 := f % 10 if (v == 0 && iMod10 == 1 && iMod100 != 11) || (fMod10 == 1 && fMod100 != 11) { return locales.PluralRuleOne @@ -145,3 +145,38 @@ func (sr *sr_Cyrl_ME) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'sr_Cyrl_ME' 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 (sr *sr_Cyrl_ME) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(sr.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, sr.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, sr.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, sr.Percent[0]) + + return b +} diff --git a/sr_Cyrl_RS/sr_Cyrl_RS.go b/sr_Cyrl_RS/sr_Cyrl_RS.go index 99f7be02..14ef556d 100644 --- a/sr_Cyrl_RS/sr_Cyrl_RS.go +++ b/sr_Cyrl_RS/sr_Cyrl_RS.go @@ -145,3 +145,38 @@ func (sr *sr_Cyrl_RS) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'sr_Cyrl_RS' 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 (sr *sr_Cyrl_RS) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(sr.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, sr.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, sr.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, sr.Percent[0]) + + return b +} diff --git a/sr_Cyrl_XK/sr_Cyrl_XK.go b/sr_Cyrl_XK/sr_Cyrl_XK.go index 4c1c983f..ee80ee53 100644 --- a/sr_Cyrl_XK/sr_Cyrl_XK.go +++ b/sr_Cyrl_XK/sr_Cyrl_XK.go @@ -145,3 +145,38 @@ func (sr *sr_Cyrl_XK) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'sr_Cyrl_XK' 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 (sr *sr_Cyrl_XK) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(sr.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, sr.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, sr.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, sr.Percent[0]) + + return b +} diff --git a/sr_Latn/sr_Latn.go b/sr_Latn/sr_Latn.go index ab55c74d..cde8e9e0 100644 --- a/sr_Latn/sr_Latn.go +++ b/sr_Latn/sr_Latn.go @@ -55,8 +55,8 @@ func (sr *sr_Latn) CardinalPluralRule(num float64, v uint64) locales.PluralRule n := math.Abs(num) i := int64(n) f := locales.F(n, v) - iMod100 := i % 100 iMod10 := i % 10 + iMod100 := i % 100 fMod10 := f % 10 fMod100 := f % 100 @@ -145,3 +145,38 @@ func (sr *sr_Latn) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'sr_Latn' 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 (sr *sr_Latn) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(sr.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, sr.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, sr.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, sr.Percent[0]) + + return b +} diff --git a/sr_Latn_BA/sr_Latn_BA.go b/sr_Latn_BA/sr_Latn_BA.go index f87f3e41..9dc0df88 100644 --- a/sr_Latn_BA/sr_Latn_BA.go +++ b/sr_Latn_BA/sr_Latn_BA.go @@ -55,8 +55,8 @@ func (sr *sr_Latn_BA) CardinalPluralRule(num float64, v uint64) locales.PluralRu n := math.Abs(num) i := int64(n) f := locales.F(n, v) - iMod100 := i % 100 iMod10 := i % 10 + iMod100 := i % 100 fMod10 := f % 10 fMod100 := f % 100 @@ -145,3 +145,38 @@ func (sr *sr_Latn_BA) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'sr_Latn_BA' 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 (sr *sr_Latn_BA) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(sr.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, sr.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, sr.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, sr.Percent[0]) + + return b +} diff --git a/sr_Latn_ME/sr_Latn_ME.go b/sr_Latn_ME/sr_Latn_ME.go index ed7d6e50..be22be96 100644 --- a/sr_Latn_ME/sr_Latn_ME.go +++ b/sr_Latn_ME/sr_Latn_ME.go @@ -55,8 +55,8 @@ func (sr *sr_Latn_ME) CardinalPluralRule(num float64, v uint64) locales.PluralRu n := math.Abs(num) i := int64(n) f := locales.F(n, v) - iMod10 := i % 10 iMod100 := i % 100 + iMod10 := i % 10 fMod10 := f % 10 fMod100 := f % 100 @@ -145,3 +145,38 @@ func (sr *sr_Latn_ME) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'sr_Latn_ME' 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 (sr *sr_Latn_ME) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(sr.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, sr.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, sr.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, sr.Percent[0]) + + return b +} diff --git a/sr_Latn_RS/sr_Latn_RS.go b/sr_Latn_RS/sr_Latn_RS.go index 1cee67c8..f5dac59f 100644 --- a/sr_Latn_RS/sr_Latn_RS.go +++ b/sr_Latn_RS/sr_Latn_RS.go @@ -145,3 +145,38 @@ func (sr *sr_Latn_RS) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'sr_Latn_RS' 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 (sr *sr_Latn_RS) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(sr.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, sr.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, sr.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, sr.Percent[0]) + + return b +} diff --git a/sr_Latn_XK/sr_Latn_XK.go b/sr_Latn_XK/sr_Latn_XK.go index 038722a8..892b801d 100644 --- a/sr_Latn_XK/sr_Latn_XK.go +++ b/sr_Latn_XK/sr_Latn_XK.go @@ -145,3 +145,38 @@ func (sr *sr_Latn_XK) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'sr_Latn_XK' 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 (sr *sr_Latn_XK) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(sr.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, sr.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, sr.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, sr.Percent[0]) + + return b +} @@ -132,3 +132,45 @@ func (sv *sv) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'sv' 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 (sv *sv) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(sv.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + for j := len(sv.decimal) - 1; j >= 0; j-- { + b = append(b, sv.decimal[j]) + } + + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(sv.minus) - 1; j >= 0; j-- { + b = append(b, sv.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + for j := len(sv.percent) - 1; j >= 0; j-- { + b = append(b, sv.percent[j]) + } + + return b +} diff --git a/sv_AX/sv_AX.go b/sv_AX/sv_AX.go index 78f6f8f5..2919cab3 100644 --- a/sv_AX/sv_AX.go +++ b/sv_AX/sv_AX.go @@ -66,8 +66,8 @@ func (sv *sv_AX) CardinalPluralRule(num float64, v uint64) locales.PluralRule { func (sv *sv_AX) OrdinalPluralRule(num float64, v uint64) locales.PluralRule { n := math.Abs(num) - nMod10 := math.Mod(n, 10) nMod100 := math.Mod(n, 100) + nMod10 := math.Mod(n, 10) if (nMod10 == 1 || nMod10 == 2) && (nMod100 != 11 && nMod100 != 12) { return locales.PluralRuleOne @@ -132,3 +132,45 @@ func (sv *sv_AX) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'sv_AX' 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 (sv *sv_AX) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(sv.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + for j := len(sv.decimal) - 1; j >= 0; j-- { + b = append(b, sv.decimal[j]) + } + + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(sv.minus) - 1; j >= 0; j-- { + b = append(b, sv.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + for j := len(sv.percent) - 1; j >= 0; j-- { + b = append(b, sv.percent[j]) + } + + return b +} diff --git a/sv_FI/sv_FI.go b/sv_FI/sv_FI.go index c7294635..46a80607 100644 --- a/sv_FI/sv_FI.go +++ b/sv_FI/sv_FI.go @@ -132,3 +132,45 @@ func (sv *sv_FI) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'sv_FI' 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 (sv *sv_FI) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(sv.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + for j := len(sv.decimal) - 1; j >= 0; j-- { + b = append(b, sv.decimal[j]) + } + + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(sv.minus) - 1; j >= 0; j-- { + b = append(b, sv.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + for j := len(sv.percent) - 1; j >= 0; j-- { + b = append(b, sv.percent[j]) + } + + return b +} diff --git a/sv_SE/sv_SE.go b/sv_SE/sv_SE.go index 9689d395..f61e7c11 100644 --- a/sv_SE/sv_SE.go +++ b/sv_SE/sv_SE.go @@ -132,3 +132,45 @@ func (sv *sv_SE) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'sv_SE' 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 (sv *sv_SE) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(sv.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + for j := len(sv.decimal) - 1; j >= 0; j-- { + b = append(b, sv.decimal[j]) + } + + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(sv.minus) - 1; j >= 0; j-- { + b = append(b, sv.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + for j := len(sv.percent) - 1; j >= 0; j-- { + b = append(b, sv.percent[j]) + } + + return b +} @@ -126,3 +126,38 @@ func (sw *sw) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'sw' 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 (sw *sw) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(sw.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, sw.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, sw.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, sw.Percent[0]) + + return b +} diff --git a/sw_CD/sw_CD.go b/sw_CD/sw_CD.go index e65f1a73..1bf39b14 100644 --- a/sw_CD/sw_CD.go +++ b/sw_CD/sw_CD.go @@ -126,3 +126,38 @@ func (sw *sw_CD) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'sw_CD' 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 (sw *sw_CD) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(sw.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, sw.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, sw.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, sw.Percent[0]) + + return b +} diff --git a/sw_KE/sw_KE.go b/sw_KE/sw_KE.go index b3dcc6c4..2f570270 100644 --- a/sw_KE/sw_KE.go +++ b/sw_KE/sw_KE.go @@ -126,3 +126,38 @@ func (sw *sw_KE) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'sw_KE' 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 (sw *sw_KE) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(sw.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, sw.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, sw.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, sw.Percent[0]) + + return b +} diff --git a/sw_TZ/sw_TZ.go b/sw_TZ/sw_TZ.go index 9e5960e7..2b431d28 100644 --- a/sw_TZ/sw_TZ.go +++ b/sw_TZ/sw_TZ.go @@ -126,3 +126,38 @@ func (sw *sw_TZ) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'sw_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 (sw *sw_TZ) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(sw.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, sw.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, sw.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, sw.Percent[0]) + + return b +} diff --git a/sw_UG/sw_UG.go b/sw_UG/sw_UG.go index 2b9fd578..d98e75a0 100644 --- a/sw_UG/sw_UG.go +++ b/sw_UG/sw_UG.go @@ -126,3 +126,38 @@ func (sw *sw_UG) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'sw_UG' 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 (sw *sw_UG) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(sw.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, sw.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, sw.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, sw.Percent[0]) + + return b +} @@ -134,3 +134,38 @@ func (ta *ta) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'ta' 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 (ta *ta) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(ta.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, ta.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, ta.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, ta.Percent[0]) + + return b +} diff --git a/ta_IN/ta_IN.go b/ta_IN/ta_IN.go index d742ef4a..20f0066f 100644 --- a/ta_IN/ta_IN.go +++ b/ta_IN/ta_IN.go @@ -134,3 +134,38 @@ func (ta *ta_IN) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'ta_IN' 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 (ta *ta_IN) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(ta.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, ta.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, ta.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, ta.Percent[0]) + + return b +} diff --git a/ta_LK/ta_LK.go b/ta_LK/ta_LK.go index b4f862ee..df628d89 100644 --- a/ta_LK/ta_LK.go +++ b/ta_LK/ta_LK.go @@ -134,3 +134,38 @@ func (ta *ta_LK) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'ta_LK' 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 (ta *ta_LK) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(ta.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, ta.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, ta.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, ta.Percent[0]) + + return b +} diff --git a/ta_MY/ta_MY.go b/ta_MY/ta_MY.go index 7627d2e7..b30df2fd 100644 --- a/ta_MY/ta_MY.go +++ b/ta_MY/ta_MY.go @@ -125,3 +125,38 @@ func (ta *ta_MY) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'ta_MY' 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 (ta *ta_MY) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(ta.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, ta.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, ta.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, ta.Percent[0]) + + return b +} diff --git a/ta_SG/ta_SG.go b/ta_SG/ta_SG.go index e65ac91e..f73a15a0 100644 --- a/ta_SG/ta_SG.go +++ b/ta_SG/ta_SG.go @@ -125,3 +125,38 @@ func (ta *ta_SG) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'ta_SG' 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 (ta *ta_SG) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(ta.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, ta.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, ta.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, ta.Percent[0]) + + return b +} @@ -134,3 +134,38 @@ func (te *te) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'te' 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 (te *te) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(te.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, te.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, te.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, te.Percent[0]) + + return b +} diff --git a/te_IN/te_IN.go b/te_IN/te_IN.go index 7e0b2b1e..d9b80094 100644 --- a/te_IN/te_IN.go +++ b/te_IN/te_IN.go @@ -134,3 +134,38 @@ func (te *te_IN) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'te_IN' 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 (te *te_IN) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(te.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, te.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, te.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, te.Percent[0]) + + return b +} @@ -79,3 +79,13 @@ func (teo *teo) 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 'teo' 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 (teo *teo) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + return []byte(s) +} diff --git a/teo_KE/teo_KE.go b/teo_KE/teo_KE.go index 64c3b01e..8c229ce0 100644 --- a/teo_KE/teo_KE.go +++ b/teo_KE/teo_KE.go @@ -79,3 +79,13 @@ func (teo *teo_KE) 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 'teo_KE' 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 (teo *teo_KE) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + return []byte(s) +} diff --git a/teo_UG/teo_UG.go b/teo_UG/teo_UG.go index e5e293a7..5fb119c0 100644 --- a/teo_UG/teo_UG.go +++ b/teo_UG/teo_UG.go @@ -79,3 +79,13 @@ func (teo *teo_UG) 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 'teo_UG' 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 (teo *teo_UG) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + return []byte(s) +} @@ -107,3 +107,38 @@ func (th *th) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'th' 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 (th *th) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(th.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, th.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, th.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, th.Percent[0]) + + return b +} diff --git a/th_TH/th_TH.go b/th_TH/th_TH.go index 80660c84..0df38fe3 100644 --- a/th_TH/th_TH.go +++ b/th_TH/th_TH.go @@ -107,3 +107,38 @@ func (th *th_TH) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'th_TH' 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 (th *th_TH) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(th.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, th.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, th.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, th.Percent[0]) + + return b +} @@ -79,3 +79,13 @@ func (ti *ti) 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 'ti' 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 (ti *ti) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + return []byte(s) +} diff --git a/ti_ER/ti_ER.go b/ti_ER/ti_ER.go index b8ff4293..b6da04e9 100644 --- a/ti_ER/ti_ER.go +++ b/ti_ER/ti_ER.go @@ -79,3 +79,13 @@ func (ti *ti_ER) 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 'ti_ER' 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 (ti *ti_ER) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + return []byte(s) +} diff --git a/ti_ET/ti_ET.go b/ti_ET/ti_ET.go index 895128ef..52712912 100644 --- a/ti_ET/ti_ET.go +++ b/ti_ET/ti_ET.go @@ -79,3 +79,13 @@ func (ti *ti_ET) 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 'ti_ET' 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 (ti *ti_ET) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + return []byte(s) +} @@ -117,3 +117,38 @@ func (tk *tk) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'tk' 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 (tk *tk) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(tk.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, tk.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, tk.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, tk.Percent[0]) + + return b +} diff --git a/tk_TM/tk_TM.go b/tk_TM/tk_TM.go index f053b355..60c587de 100644 --- a/tk_TM/tk_TM.go +++ b/tk_TM/tk_TM.go @@ -117,3 +117,38 @@ func (tk *tk_TM) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'tk_TM' 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 (tk *tk_TM) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(tk.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, tk.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, tk.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, tk.Percent[0]) + + return b +} @@ -107,3 +107,38 @@ func (to *to) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'to' 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 (to *to) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(to.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, to.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, to.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, to.Percent[0]) + + return b +} diff --git a/to_TO/to_TO.go b/to_TO/to_TO.go index be7fab48..40b15459 100644 --- a/to_TO/to_TO.go +++ b/to_TO/to_TO.go @@ -107,3 +107,38 @@ func (to *to_TO) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'to_TO' 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 (to *to_TO) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(to.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, to.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, to.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, to.Percent[0]) + + return b +} @@ -125,3 +125,38 @@ func (tr *tr) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'tr' 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 (tr *tr) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(tr.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, tr.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, tr.minus[0]) + } + + b = append(b, tr.Percent[0]) + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + return b +} diff --git a/tr_CY/tr_CY.go b/tr_CY/tr_CY.go index b96c2e9b..44598b8e 100644 --- a/tr_CY/tr_CY.go +++ b/tr_CY/tr_CY.go @@ -125,3 +125,38 @@ func (tr *tr_CY) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'tr_CY' 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 (tr *tr_CY) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(tr.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, tr.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, tr.minus[0]) + } + + b = append(b, tr.Percent[0]) + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + return b +} diff --git a/tr_TR/tr_TR.go b/tr_TR/tr_TR.go index 22da2713..2f69d8ab 100644 --- a/tr_TR/tr_TR.go +++ b/tr_TR/tr_TR.go @@ -125,3 +125,38 @@ func (tr *tr_TR) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'tr_TR' 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 (tr *tr_TR) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(tr.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, tr.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, tr.minus[0]) + } + + b = append(b, tr.Percent[0]) + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + return b +} @@ -112,3 +112,42 @@ func (twq *twq) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'twq' 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 (twq *twq) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(twq.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, twq.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(twq.minus) - 1; j >= 0; j-- { + b = append(b, twq.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + for j := len(twq.percent) - 1; j >= 0; j-- { + b = append(b, twq.percent[j]) + } + + return b +} diff --git a/twq_NE/twq_NE.go b/twq_NE/twq_NE.go index 7dd38bd5..ea93f303 100644 --- a/twq_NE/twq_NE.go +++ b/twq_NE/twq_NE.go @@ -112,3 +112,42 @@ func (twq *twq_NE) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'twq_NE' 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 (twq *twq_NE) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(twq.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, twq.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(twq.minus) - 1; j >= 0; j-- { + b = append(b, twq.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + for j := len(twq.percent) - 1; j >= 0; j-- { + b = append(b, twq.percent[j]) + } + + return b +} @@ -79,3 +79,13 @@ func (tzm *tzm) 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 'tzm' 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 (tzm *tzm) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + return []byte(s) +} diff --git a/tzm_MA/tzm_MA.go b/tzm_MA/tzm_MA.go index 8d3ee1be..e3539748 100644 --- a/tzm_MA/tzm_MA.go +++ b/tzm_MA/tzm_MA.go @@ -79,3 +79,13 @@ func (tzm *tzm_MA) 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 'tzm_MA' 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 (tzm *tzm_MA) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + return []byte(s) +} @@ -125,3 +125,38 @@ func (ug *ug) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'ug' 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 (ug *ug) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(ug.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, ug.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, ug.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, ug.Percent[0]) + + return b +} diff --git a/ug_CN/ug_CN.go b/ug_CN/ug_CN.go index a9d85b8a..b6b63106 100644 --- a/ug_CN/ug_CN.go +++ b/ug_CN/ug_CN.go @@ -125,3 +125,38 @@ func (ug *ug_CN) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'ug_CN' 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 (ug *ug_CN) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(ug.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, ug.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, ug.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, ug.Percent[0]) + + return b +} @@ -170,3 +170,38 @@ func (uk *uk) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'uk' 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 (uk *uk) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(uk.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, uk.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, uk.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, uk.Percent[0]) + + return b +} diff --git a/uk_UA/uk_UA.go b/uk_UA/uk_UA.go index 274bbe33..b01430bf 100644 --- a/uk_UA/uk_UA.go +++ b/uk_UA/uk_UA.go @@ -170,3 +170,38 @@ func (uk *uk_UA) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'uk_UA' 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 (uk *uk_UA) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(uk.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, uk.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, uk.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, uk.Percent[0]) + + return b +} @@ -117,3 +117,40 @@ func (ur *ur) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'ur' 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 (ur *ur) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(ur.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, ur.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(ur.minus) - 1; j >= 0; j-- { + b = append(b, ur.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, ur.Percent[0]) + + return b +} diff --git a/ur_IN/ur_IN.go b/ur_IN/ur_IN.go index a99f2906..36acc3f8 100644 --- a/ur_IN/ur_IN.go +++ b/ur_IN/ur_IN.go @@ -117,3 +117,40 @@ func (ur *ur_IN) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'ur_IN' 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 (ur *ur_IN) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(ur.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, ur.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(ur.minus) - 1; j >= 0; j-- { + b = append(b, ur.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, ur.Percent[0]) + + return b +} diff --git a/ur_PK/ur_PK.go b/ur_PK/ur_PK.go index 7e9ac2ed..bbee2174 100644 --- a/ur_PK/ur_PK.go +++ b/ur_PK/ur_PK.go @@ -117,3 +117,40 @@ func (ur *ur_PK) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'ur_PK' 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 (ur *ur_PK) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(ur.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, ur.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(ur.minus) - 1; j >= 0; j-- { + b = append(b, ur.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, ur.Percent[0]) + + return b +} @@ -131,3 +131,43 @@ func (uz *uz) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'uz' 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 (uz *uz) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(uz.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + for j := len(uz.decimal) - 1; j >= 0; j-- { + b = append(b, uz.decimal[j]) + } + + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, uz.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + for j := len(uz.percent) - 1; j >= 0; j-- { + b = append(b, uz.percent[j]) + } + + return b +} diff --git a/uz_Arab/uz_Arab.go b/uz_Arab/uz_Arab.go index 90abb9ee..f8c717bb 100644 --- a/uz_Arab/uz_Arab.go +++ b/uz_Arab/uz_Arab.go @@ -131,3 +131,43 @@ func (uz *uz_Arab) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'uz_Arab' 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 (uz *uz_Arab) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(uz.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + for j := len(uz.decimal) - 1; j >= 0; j-- { + b = append(b, uz.decimal[j]) + } + + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, uz.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + for j := len(uz.percent) - 1; j >= 0; j-- { + b = append(b, uz.percent[j]) + } + + return b +} diff --git a/uz_Arab_AF/uz_Arab_AF.go b/uz_Arab_AF/uz_Arab_AF.go index f9e1351e..fac44429 100644 --- a/uz_Arab_AF/uz_Arab_AF.go +++ b/uz_Arab_AF/uz_Arab_AF.go @@ -131,3 +131,43 @@ func (uz *uz_Arab_AF) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'uz_Arab_AF' 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 (uz *uz_Arab_AF) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(uz.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + for j := len(uz.decimal) - 1; j >= 0; j-- { + b = append(b, uz.decimal[j]) + } + + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, uz.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + for j := len(uz.percent) - 1; j >= 0; j-- { + b = append(b, uz.percent[j]) + } + + return b +} diff --git a/uz_Cyrl/uz_Cyrl.go b/uz_Cyrl/uz_Cyrl.go index 4f22ce53..655c87c2 100644 --- a/uz_Cyrl/uz_Cyrl.go +++ b/uz_Cyrl/uz_Cyrl.go @@ -131,3 +131,43 @@ func (uz *uz_Cyrl) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'uz_Cyrl' 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 (uz *uz_Cyrl) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(uz.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + for j := len(uz.decimal) - 1; j >= 0; j-- { + b = append(b, uz.decimal[j]) + } + + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, uz.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + for j := len(uz.percent) - 1; j >= 0; j-- { + b = append(b, uz.percent[j]) + } + + return b +} diff --git a/uz_Cyrl_UZ/uz_Cyrl_UZ.go b/uz_Cyrl_UZ/uz_Cyrl_UZ.go index adf22699..66d0bad9 100644 --- a/uz_Cyrl_UZ/uz_Cyrl_UZ.go +++ b/uz_Cyrl_UZ/uz_Cyrl_UZ.go @@ -131,3 +131,43 @@ func (uz *uz_Cyrl_UZ) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'uz_Cyrl_UZ' 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 (uz *uz_Cyrl_UZ) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(uz.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + for j := len(uz.decimal) - 1; j >= 0; j-- { + b = append(b, uz.decimal[j]) + } + + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, uz.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + for j := len(uz.percent) - 1; j >= 0; j-- { + b = append(b, uz.percent[j]) + } + + return b +} diff --git a/uz_Latn/uz_Latn.go b/uz_Latn/uz_Latn.go index e79250bb..4fed3780 100644 --- a/uz_Latn/uz_Latn.go +++ b/uz_Latn/uz_Latn.go @@ -131,3 +131,43 @@ func (uz *uz_Latn) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'uz_Latn' 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 (uz *uz_Latn) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(uz.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + for j := len(uz.decimal) - 1; j >= 0; j-- { + b = append(b, uz.decimal[j]) + } + + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, uz.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + for j := len(uz.percent) - 1; j >= 0; j-- { + b = append(b, uz.percent[j]) + } + + return b +} diff --git a/uz_Latn_UZ/uz_Latn_UZ.go b/uz_Latn_UZ/uz_Latn_UZ.go index f1247509..ee4042c7 100644 --- a/uz_Latn_UZ/uz_Latn_UZ.go +++ b/uz_Latn_UZ/uz_Latn_UZ.go @@ -131,3 +131,43 @@ func (uz *uz_Latn_UZ) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'uz_Latn_UZ' 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 (uz *uz_Latn_UZ) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(uz.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + for j := len(uz.decimal) - 1; j >= 0; j-- { + b = append(b, uz.decimal[j]) + } + + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, uz.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + for j := len(uz.percent) - 1; j >= 0; j-- { + b = append(b, uz.percent[j]) + } + + return b +} @@ -109,3 +109,13 @@ func (vai *vai) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'vai' 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 (vai *vai) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + return []byte(s) +} diff --git a/vai_Latn/vai_Latn.go b/vai_Latn/vai_Latn.go index 9fcc92ea..b84221c5 100644 --- a/vai_Latn/vai_Latn.go +++ b/vai_Latn/vai_Latn.go @@ -109,3 +109,13 @@ func (vai *vai_Latn) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'vai_Latn' 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 (vai *vai_Latn) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + return []byte(s) +} diff --git a/vai_Latn_LR/vai_Latn_LR.go b/vai_Latn_LR/vai_Latn_LR.go index b3a242f2..bce65f99 100644 --- a/vai_Latn_LR/vai_Latn_LR.go +++ b/vai_Latn_LR/vai_Latn_LR.go @@ -109,3 +109,13 @@ func (vai *vai_Latn_LR) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'vai_Latn_LR' 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 (vai *vai_Latn_LR) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + return []byte(s) +} diff --git a/vai_Vaii/vai_Vaii.go b/vai_Vaii/vai_Vaii.go index 5f7defda..e0270957 100644 --- a/vai_Vaii/vai_Vaii.go +++ b/vai_Vaii/vai_Vaii.go @@ -109,3 +109,13 @@ func (vai *vai_Vaii) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'vai_Vaii' 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 (vai *vai_Vaii) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + return []byte(s) +} diff --git a/vai_Vaii_LR/vai_Vaii_LR.go b/vai_Vaii_LR/vai_Vaii_LR.go index 3f253a5d..ebd9e0a1 100644 --- a/vai_Vaii_LR/vai_Vaii_LR.go +++ b/vai_Vaii_LR/vai_Vaii_LR.go @@ -109,3 +109,13 @@ func (vai *vai_Vaii_LR) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'vai_Vaii_LR' 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 (vai *vai_Vaii_LR) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + return []byte(s) +} @@ -114,3 +114,38 @@ func (vi *vi) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'vi' 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 (vi *vi) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(vi.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, vi.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, vi.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, vi.Percent[0]) + + return b +} diff --git a/vi_VN/vi_VN.go b/vi_VN/vi_VN.go index 08fa28bd..1ab40d35 100644 --- a/vi_VN/vi_VN.go +++ b/vi_VN/vi_VN.go @@ -114,3 +114,38 @@ func (vi *vi_VN) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'vi_VN' 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 (vi *vi_VN) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(vi.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, vi.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, vi.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, vi.Percent[0]) + + return b +} @@ -79,3 +79,13 @@ func (vo *vo) 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 'vo' 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 (vo *vo) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + return []byte(s) +} diff --git a/vo_001/vo_001.go b/vo_001/vo_001.go index 584c7cc6..6dd5689b 100644 --- a/vo_001/vo_001.go +++ b/vo_001/vo_001.go @@ -79,3 +79,13 @@ func (vo *vo_001) 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 'vo_001' 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 (vo *vo_001) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + return []byte(s) +} @@ -79,3 +79,13 @@ func (vun *vun) 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 'vun' 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 (vun *vun) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + return []byte(s) +} diff --git a/vun_TZ/vun_TZ.go b/vun_TZ/vun_TZ.go index 27631df3..efe2c86d 100644 --- a/vun_TZ/vun_TZ.go +++ b/vun_TZ/vun_TZ.go @@ -79,3 +79,13 @@ func (vun *vun_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 'vun_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 (vun *vun_TZ) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + return []byte(s) +} @@ -79,3 +79,13 @@ func (wae *wae) 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 'wae' 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 (wae *wae) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + return []byte(s) +} diff --git a/wae_CH/wae_CH.go b/wae_CH/wae_CH.go index 116a1162..3bd8fc24 100644 --- a/wae_CH/wae_CH.go +++ b/wae_CH/wae_CH.go @@ -79,3 +79,13 @@ func (wae *wae_CH) 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 'wae_CH' 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 (wae *wae_CH) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + return []byte(s) +} @@ -79,3 +79,13 @@ func (xog *xog) 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 'xog' 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 (xog *xog) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + return []byte(s) +} diff --git a/xog_UG/xog_UG.go b/xog_UG/xog_UG.go index 23291776..74a7b0ce 100644 --- a/xog_UG/xog_UG.go +++ b/xog_UG/xog_UG.go @@ -79,3 +79,13 @@ func (xog *xog_UG) 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 'xog_UG' 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 (xog *xog_UG) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + return []byte(s) +} @@ -112,3 +112,42 @@ func (yav *yav) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'yav' 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 (yav *yav) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(yav.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, yav.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(yav.minus) - 1; j >= 0; j-- { + b = append(b, yav.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + for j := len(yav.percent) - 1; j >= 0; j-- { + b = append(b, yav.percent[j]) + } + + return b +} diff --git a/yav_CM/yav_CM.go b/yav_CM/yav_CM.go index c02e898c..5a7a9e2d 100644 --- a/yav_CM/yav_CM.go +++ b/yav_CM/yav_CM.go @@ -112,3 +112,42 @@ func (yav *yav_CM) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'yav_CM' 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 (yav *yav_CM) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(yav.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, yav.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(yav.minus) - 1; j >= 0; j-- { + b = append(b, yav.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + for j := len(yav.percent) - 1; j >= 0; j-- { + b = append(b, yav.percent[j]) + } + + return b +} @@ -80,3 +80,13 @@ func (yi *yi) 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 'yi' 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 (yi *yi) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + return []byte(s) +} diff --git a/yi_001/yi_001.go b/yi_001/yi_001.go index d9994566..e9dd5b31 100644 --- a/yi_001/yi_001.go +++ b/yi_001/yi_001.go @@ -80,3 +80,13 @@ func (yi *yi_001) 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 'yi_001' 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 (yi *yi_001) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + return []byte(s) +} @@ -72,3 +72,13 @@ func (yo *yo) 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 'yo' 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 (yo *yo) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + return []byte(s) +} diff --git a/yo_BJ/yo_BJ.go b/yo_BJ/yo_BJ.go index 07e05ff9..46a5d439 100644 --- a/yo_BJ/yo_BJ.go +++ b/yo_BJ/yo_BJ.go @@ -72,3 +72,13 @@ func (yo *yo_BJ) 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 'yo_BJ' 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 (yo *yo_BJ) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + return []byte(s) +} diff --git a/yo_NG/yo_NG.go b/yo_NG/yo_NG.go index ea766bfa..16484375 100644 --- a/yo_NG/yo_NG.go +++ b/yo_NG/yo_NG.go @@ -72,3 +72,13 @@ func (yo *yo_NG) 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 'yo_NG' 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 (yo *yo_NG) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + return []byte(s) +} @@ -107,3 +107,38 @@ func (yue *yue) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'yue' 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 (yue *yue) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(yue.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, yue.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, yue.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, yue.Percent[0]) + + return b +} diff --git a/yue_HK/yue_HK.go b/yue_HK/yue_HK.go index 281c89ca..18cdbb24 100644 --- a/yue_HK/yue_HK.go +++ b/yue_HK/yue_HK.go @@ -107,3 +107,38 @@ func (yue *yue_HK) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'yue_HK' 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 (yue *yue_HK) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(yue.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, yue.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, yue.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, yue.Percent[0]) + + return b +} @@ -72,3 +72,42 @@ func (zgh *zgh) 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 'zgh' 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 (zgh *zgh) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(zgh.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, zgh.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(zgh.minus) - 1; j >= 0; j-- { + b = append(b, zgh.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + for j := len(zgh.percent) - 1; j >= 0; j-- { + b = append(b, zgh.percent[j]) + } + + return b +} diff --git a/zgh_MA/zgh_MA.go b/zgh_MA/zgh_MA.go index d19d9d3a..f6ce4024 100644 --- a/zgh_MA/zgh_MA.go +++ b/zgh_MA/zgh_MA.go @@ -72,3 +72,42 @@ func (zgh *zgh_MA) 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 'zgh_MA' 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 (zgh *zgh_MA) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(zgh.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, zgh.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + for j := len(zgh.minus) - 1; j >= 0; j-- { + b = append(b, zgh.minus[j]) + } + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + for j := len(zgh.percent) - 1; j >= 0; j-- { + b = append(b, zgh.percent[j]) + } + + return b +} @@ -107,3 +107,38 @@ func (zh *zh) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'zh' 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 (zh *zh) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(zh.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, zh.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, zh.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, zh.Percent[0]) + + return b +} diff --git a/zh_Hans/zh_Hans.go b/zh_Hans/zh_Hans.go index cd97fa2c..56b79a59 100644 --- a/zh_Hans/zh_Hans.go +++ b/zh_Hans/zh_Hans.go @@ -107,3 +107,38 @@ func (zh *zh_Hans) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'zh_Hans' 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 (zh *zh_Hans) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(zh.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, zh.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, zh.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, zh.Percent[0]) + + return b +} diff --git a/zh_Hans_CN/zh_Hans_CN.go b/zh_Hans_CN/zh_Hans_CN.go index d6e9a7af..98e236e4 100644 --- a/zh_Hans_CN/zh_Hans_CN.go +++ b/zh_Hans_CN/zh_Hans_CN.go @@ -107,3 +107,38 @@ func (zh *zh_Hans_CN) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'zh_Hans_CN' 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 (zh *zh_Hans_CN) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(zh.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, zh.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, zh.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, zh.Percent[0]) + + return b +} diff --git a/zh_Hans_HK/zh_Hans_HK.go b/zh_Hans_HK/zh_Hans_HK.go index 9ef1405b..b672a082 100644 --- a/zh_Hans_HK/zh_Hans_HK.go +++ b/zh_Hans_HK/zh_Hans_HK.go @@ -107,3 +107,38 @@ func (zh *zh_Hans_HK) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'zh_Hans_HK' 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 (zh *zh_Hans_HK) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(zh.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, zh.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, zh.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, zh.Percent[0]) + + return b +} diff --git a/zh_Hans_MO/zh_Hans_MO.go b/zh_Hans_MO/zh_Hans_MO.go index 26abbd2c..a769c9d2 100644 --- a/zh_Hans_MO/zh_Hans_MO.go +++ b/zh_Hans_MO/zh_Hans_MO.go @@ -107,3 +107,38 @@ func (zh *zh_Hans_MO) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'zh_Hans_MO' 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 (zh *zh_Hans_MO) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(zh.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, zh.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, zh.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, zh.Percent[0]) + + return b +} diff --git a/zh_Hans_SG/zh_Hans_SG.go b/zh_Hans_SG/zh_Hans_SG.go index d9dedcab..bb2db6bf 100644 --- a/zh_Hans_SG/zh_Hans_SG.go +++ b/zh_Hans_SG/zh_Hans_SG.go @@ -107,3 +107,38 @@ func (zh *zh_Hans_SG) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'zh_Hans_SG' 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 (zh *zh_Hans_SG) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(zh.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, zh.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, zh.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, zh.Percent[0]) + + return b +} diff --git a/zh_Hant/zh_Hant.go b/zh_Hant/zh_Hant.go index 358f1052..a7ae825c 100644 --- a/zh_Hant/zh_Hant.go +++ b/zh_Hant/zh_Hant.go @@ -107,3 +107,38 @@ func (zh *zh_Hant) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'zh_Hant' 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 (zh *zh_Hant) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(zh.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, zh.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, zh.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, zh.Percent[0]) + + return b +} diff --git a/zh_Hant_HK/zh_Hant_HK.go b/zh_Hant_HK/zh_Hant_HK.go index 68f08932..4a267f6f 100644 --- a/zh_Hant_HK/zh_Hant_HK.go +++ b/zh_Hant_HK/zh_Hant_HK.go @@ -107,3 +107,38 @@ func (zh *zh_Hant_HK) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'zh_Hant_HK' 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 (zh *zh_Hant_HK) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(zh.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, zh.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, zh.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, zh.Percent[0]) + + return b +} diff --git a/zh_Hant_MO/zh_Hant_MO.go b/zh_Hant_MO/zh_Hant_MO.go index f1b302cf..7d3848c4 100644 --- a/zh_Hant_MO/zh_Hant_MO.go +++ b/zh_Hant_MO/zh_Hant_MO.go @@ -107,3 +107,38 @@ func (zh *zh_Hant_MO) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'zh_Hant_MO' 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 (zh *zh_Hant_MO) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(zh.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, zh.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, zh.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, zh.Percent[0]) + + return b +} diff --git a/zh_Hant_TW/zh_Hant_TW.go b/zh_Hant_TW/zh_Hant_TW.go index 88b148c8..c946ae72 100644 --- a/zh_Hant_TW/zh_Hant_TW.go +++ b/zh_Hant_TW/zh_Hant_TW.go @@ -107,3 +107,38 @@ func (zh *zh_Hant_TW) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'zh_Hant_TW' 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 (zh *zh_Hant_TW) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(zh.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, zh.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, zh.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, zh.Percent[0]) + + return b +} @@ -126,3 +126,38 @@ func (zu *zu) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'zu' 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 (zu *zu) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(zu.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, zu.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, zu.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, zu.Percent[0]) + + return b +} diff --git a/zu_ZA/zu_ZA.go b/zu_ZA/zu_ZA.go index f71a0fa2..d8d5a4cd 100644 --- a/zu_ZA/zu_ZA.go +++ b/zu_ZA/zu_ZA.go @@ -126,3 +126,38 @@ func (zu *zu_ZA) FmtNumber(num float64, v uint64) []byte { return b } + +// FmtPercent returns 'num' with digits/precision of 'v' for 'zu_ZA' 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 (zu *zu_ZA) FmtPercent(num float64, v uint64) []byte { + + s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64) + l := len(s) + len(zu.decimal) + + b := make([]byte, 0, l) + + for i := len(s) - 1; i >= 0; i-- { + + if s[i] == '.' { + b = append(b, zu.decimal[0]) + continue + } + + b = append(b, s[i]) + } + + if num < 0 { + b = append(b, zu.minus[0]) + } + + // reverse + for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 { + b[i], b[j] = b[j], b[i] + } + + b = append(b, zu.Percent[0]) + + return b +} |