mirror of
https://github.com/ManyakRus/starter.git
synced 2025-11-26 23:10:42 +02:00
сделал RoundFloat64()
This commit is contained in:
@@ -14,6 +14,7 @@ import (
|
||||
"golang.org/x/exp/constraints"
|
||||
"google.golang.org/protobuf/types/known/timestamppb"
|
||||
"hash/fnv"
|
||||
"math"
|
||||
"os/exec"
|
||||
"reflect"
|
||||
"runtime"
|
||||
@@ -1767,3 +1768,12 @@ func StringIntWithSeparator(n int, separator rune) string {
|
||||
|
||||
return buff.String()
|
||||
}
|
||||
|
||||
// RoundFloat64 - округляет float64 до precision цифр после запятой
|
||||
// пример:
|
||||
// RoundFloat64(123.456, 2) = 123.46
|
||||
// RoundFloat64(123.456, 1) = 123.5
|
||||
func RoundFloat64(value float64, precision int) float64 {
|
||||
ratio := math.Pow(10, float64(precision))
|
||||
return math.Round(value*ratio) / ratio
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user