10 examples of 'golang round' in Go

Every line of 'golang round' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Go code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
78func funcRound(js JSWriter, args []ast.Node) {
79 switch len(args) {
80 case 1:
81 js.Write("Math.round(", args[0], ")")
82 default:
83 js.Write(
84 "Math.round(", args[0], "* Math.pow(10, ", args[1], ")) / Math.pow(10, ", args[1], ")")
85 }
86}
67func Round(x complex128, prec int) complex128 {
68 if x == 0 {
69 // Make sure zero is returned
70 // without the negative bit set.
71 return 0
72 }
73 return complex(scalar.Round(real(x), prec), scalar.Round(imag(x), prec))
74}
208func (h *Hashgraph) round(x string) (int, error) {
209 if c, ok := h.roundCache.Get(x); ok {
210 return c.(int), nil
211 }
212 r, err := h._round(x)
213 if err != nil {
214 return -1, err
215 }
216 h.roundCache.Add(x, r)
217 return r, nil
218}
421func (gf *BuiltInFunctions) Round(x float64) float64 {
422 return math.Round(x)
423}
110func roundF64(val float64, places int) float64 {
111 v, _ := strconv.ParseFloat(fmt.Sprintf("%0.3f", val), 64)
112 return v
113}
50func round(a int32, b int32) int32 {
51 return (a + b/2) / b
52}
114func round(x float64) float64 {
115 return math.Floor(x + 0.5)
116}
36func round(x float64, precision int) float64 {
37 var rounder float64
38 pow := math.Pow(10, float64(precision))
39 intermediate := x * pow
40
41 if intermediate < 0.0 {
42 intermediate -= 0.5
43 } else {
44 intermediate += 0.5
45 }
46 rounder = float64(int64(intermediate))
47
48 return rounder / float64(pow)
49}
14func Round(x float64) float64 {
15 t := math.Trunc(x)
16 if math.Abs(x-t) >= 0.5 {
17 return t + math.Copysign(1, x)
18 }
19 return t
20}
33func (s HeaderCapn) Round() uint64 { return C.Struct(s).Get64(24) }

Related snippets