Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/gohugoio/locales.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'sbp/sbp.go')
-rw-r--r--sbp/sbp.go26
1 files changed, 10 insertions, 16 deletions
diff --git a/sbp/sbp.go b/sbp/sbp.go
index 9221c747..a7775cc3 100644
--- a/sbp/sbp.go
+++ b/sbp/sbp.go
@@ -1,6 +1,7 @@
package sbp
import (
+ "math"
"strconv"
"github.com/go-playground/locales"
@@ -68,36 +69,24 @@ func (sbp *sbp) RangePluralRule(num1 float64, v1 uint64, num2 float64, v2 uint64
// avoid allocations; otherwise just cast as string.
func (sbp *sbp) FmtNumber(num float64, v uint64) []byte {
- s := strconv.FormatFloat(num, 'f', int(v), 64)
-
+ s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
l := len(s) + len(sbp.decimal) + len(sbp.group)*len(s[:len(s)-int(v)-1])/3
-
count := 0
inWhole := v == 0
-
b := make([]byte, 0, l)
for i := len(s) - 1; i >= 0; i-- {
if s[i] == '.' {
-
- for j := len(sbp.decimal) - 1; j >= 0; j-- {
- b = append(b, sbp.decimal[j])
- }
-
+ b = append(b, sbp.decimal[0])
inWhole = true
continue
}
if inWhole {
-
if count == 3 {
-
- for j := len(sbp.group) - 1; j >= 0; j-- {
- b = append(b, sbp.group[j])
- }
-
+ b = append(b, sbp.group[0])
count = 1
} else {
count++
@@ -107,11 +96,16 @@ func (sbp *sbp) FmtNumber(num float64, v uint64) []byte {
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]
}
return b
-
}