Skip to content

Commit 8f49312

Browse files
author
Jaybeecave
committed
ToFixed Int
1 parent c100f4f commit 8f49312

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

helpers.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package helpers
22

33
import (
4+
"math"
45
"strconv"
56
"strings"
67
"unicode"
@@ -82,6 +83,11 @@ func Round(val float64) int {
8283
return int(val + 0.5)
8384
}
8485

86+
func ToFixed(num float64, precision int) float64 {
87+
output := math.Pow(10, float64(precision))
88+
return float64(Round(num*output)) / output
89+
}
90+
8591
func KebabCase(in string) string {
8692
out := SnakeCase(in)
8793
out = strings.Replace(out, "_", "-", -1)

0 commit comments

Comments
 (0)