diff options
Diffstat (limited to 'mt_MT/mt_MT.go')
-rw-r--r-- | mt_MT/mt_MT.go | 23 |
1 files changed, 7 insertions, 16 deletions
diff --git a/mt_MT/mt_MT.go b/mt_MT/mt_MT.go index 9c19f4d3..7d69b2c6 100644 --- a/mt_MT/mt_MT.go +++ b/mt_MT/mt_MT.go @@ -81,36 +81,24 @@ func (mt *mt_MT) RangePluralRule(num1 float64, v1 uint64, num2 float64, v2 uint6 // avoid allocations; otherwise just cast as string. func (mt *mt_MT) 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(mt.decimal) + len(mt.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(mt.decimal) - 1; j >= 0; j-- { - b = append(b, mt.decimal[j]) - } - + b = append(b, mt.decimal[0]) inWhole = true continue } if inWhole { - if count == 3 { - - for j := len(mt.group) - 1; j >= 0; j-- { - b = append(b, mt.group[j]) - } - + b = append(b, mt.group[0]) count = 1 } else { count++ @@ -120,11 +108,14 @@ func (mt *mt_MT) FmtNumber(num float64, v uint64) []byte { 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] } return b - } |