You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
15 lines
258 B
Go
15 lines
258 B
Go
2 years ago
|
package utils
|
||
|
|
||
|
import (
|
||
|
"math"
|
||
|
"strconv"
|
||
|
|
||
|
"github.com/spf13/cast"
|
||
|
)
|
||
|
|
||
|
func FormatFloat(f float64, dig int) float64 {
|
||
|
result := cast.ToFloat64(strconv.FormatFloat(f, 'f', dig+1, 64))
|
||
|
pow := math.Pow(1, float64(dig))
|
||
|
return math.Round(result*pow) / pow
|
||
|
}
|