MCPcopy
hub / github.com/Masterminds/sprig / round

Function round

numeric.go:107–125  ·  view source on GitHub ↗
(a interface{}, p int, rOpt ...float64)

Source from the content-addressed store, hash-verified

105}
106
107func round(a interface{}, p int, rOpt ...float64) float64 {
108 roundOn := .5
109 if len(rOpt) > 0 {
110 roundOn = rOpt[0]
111 }
112 val := toFloat64(a)
113 places := toFloat64(p)
114
115 var round float64
116 pow := math.Pow(10, places)
117 digit := pow * val
118 _, div := math.Modf(digit)
119 if div >= roundOn {
120 round = math.Ceil(digit)
121 } else {
122 round = math.Floor(digit)
123 }
124 return round / pow
125}
126
127// converts unix octal to decimal
128func toDecimal(v interface{}) int64 {

Callers 1

TestRoundFunction · 0.85

Calls 1

toFloat64Function · 0.85

Tested by 1

TestRoundFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…