MCPcopy Create free account
hub / github.com/cockroachdb/apd / ExampleContext_Quantize

Function ExampleContext_Quantize

example_test.go:67–87  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

65}
66
67func ExampleContext_Quantize() {
68 input, _, _ := apd.NewFromString("123.45")
69 output := new(apd.Decimal)
70 c := apd.BaseContext.WithPrecision(10)
71 for i := int32(-3); i <= 3; i++ {
72 res, _ := c.Quantize(output, input, i)
73 fmt.Printf("%2v: %s", i, output)
74 if res != 0 {
75 fmt.Printf(" (%s)", res)
76 }
77 fmt.Println()
78 }
79 // Output:
80 // -3: 123.450
81 // -2: 123.45
82 // -1: 123.5 (inexact, rounded)
83 // 0: 123 (inexact, rounded)
84 // 1: 1.2E+2 (inexact, rounded)
85 // 2: 1E+2 (inexact, rounded)
86 // 3: 0E+3 (inexact, rounded)
87}
88
89func ExampleErrDecimal() {
90 c := apd.BaseContext.WithPrecision(5)

Callers

nothing calls this directly

Calls 3

NewFromStringMethod · 0.80
WithPrecisionMethod · 0.80
QuantizeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…