10 examples of 'golang decimal' in Go

Every line of 'golang decimal' 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
this disclaimer
1605func (s *ConstantContext) DECIMAL() antlr.TerminalNode {
1606 return s.GetToken(oncrpcv2ParserDECIMAL, 0)
1607}
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

98func decimal(s string, scale int) string {
99 if scale == 0 {
100 return ""
101 }
102
103 if len(s) >= scale {
104 return "." + s[len(s)-scale:]
105 }
106
107 r := make([]byte, scale)
108 for i := range r {
109 r[i] = 0x30
110 }
111
112 copy(r[scale-len(s):], s)
113
114 return "." + string(r)
115}
634func (s *VertexContext) AllDECIMAL() []antlr.TerminalNode {
635 return s.GetTokens(WavefrontOBJParserDECIMAL)
636}
67func FixedDecimal(amount float64) float64 {
68 return m.FixedFloat(amount, 2)
69}
554func (s *GruleParserListener) EnterDecimalLiteral(ctx *parser.DecimalLiteralContext) {
555 Logger.Tracef("Entering decimal literal '%s'", ctx.GetText())
556}
398func (d *jsonBinaryDecoder) decodeDecimal(data []byte) interface{} {
399 precision := int(data[0])
400 scale := int(data[1])
401
402 v, _, err := decodeDecimal(data[2:], precision, scale, d.useDecimal)
403 d.err = err
404
405 return v
406}
8func IsDecimal(b byte) bool {
9 return b >= '0' && b <= '9'
10}
69func (s ValueSet) ParseDecimal(val uint64) string {
70 if v, ok := s[val]; ok {
71 return v
72 }
73 return fmt.Sprintf("%d", val)
74}
8func fractionToDecimal(n int, d int) string {
9 if n == 0 {
10 return "0"
11 }
12
13 if n*d < 0 {
14 // n, d 异号,则结果前面有负号
15 return "-" + fractionToDecimal(abs(n), abs(d))
16 }
17
18 // 确保 n 和 d 是非负数
19 n, d = abs(n), abs(d)
20
21 if n >= d {
22 // n / d 的小数部分
23 ds := fractionToDecimal(n%d, d)
24 return strconv.Itoa(n/d) + ds[1:]
25 }
26
27 // digits 用来保存 n/d 的结果
28 digits := make([]byte, 2, 1024)
29 digits[0] = '0'
30 digits[1] = '.'
31 // idx 是 n/d 的结果的在 digits 的索引号
32 idx := 2
33 // rec[n] = idx
34 rec := make(map[int]int, 1024)
35 for {
36 if i, ok := rec[n]; ok {
37 // n 重复出现,则说明 n/d 是下一个循环的开始
38 // 循环部分的起点,就是 n 上次出现的 idx 值
39 return fmt.Sprintf("%s(%s)", string(digits[:i]), string(digits[i:]))
40 }
41
42 rec[n] = idx
43
44 n *= 10
45 idx++
46
47 digits = append(digits, byte(n/d)+'0')
48 n %= d
49
50 if n == 0 {
51 // 不会有循环部分
52 return string(digits)
53 }
54 }
55}
18func DoTestDecimal380(t *testing.T) {
19 TestForEachDB("TestDecimal380", t, testDecimal380)
20 //
21}

Related snippets