mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-27 22:09:53 +02:00
tpl: Fix bad rounding in NumFmt
strconv.FormatFloat doesn't round properly sometimes, this adds a different method of rounding, fixes #7116
This commit is contained in:
committed by
Bjørn Erik Pedersen
parent
f7d909f394
commit
3d9235e8fc
@@ -102,10 +102,13 @@ func (ns *Namespace) NumFmt(precision, number interface{}, options ...interface{
|
||||
}
|
||||
}
|
||||
|
||||
exp := math.Pow(10.0, float64(prec))
|
||||
r := math.Round(n*exp) / exp
|
||||
|
||||
// Logic from MIT Licensed github.com/go-playground/locales/
|
||||
// Original Copyright (c) 2016 Go Playground
|
||||
|
||||
s := strconv.FormatFloat(math.Abs(n), 'f', prec, 64)
|
||||
s := strconv.FormatFloat(math.Abs(r), 'f', prec, 64)
|
||||
L := len(s) + 2 + len(s[:len(s)-1-prec])/3
|
||||
|
||||
var count int
|
||||
|
Reference in New Issue
Block a user