MCPcopy Create free account
hub / github.com/pquerna/ffjson / String

Method String

fflib/v1/decimal.go:22–59  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

20}
21
22func (a *decimal) String() string {
23 n := 10 + a.nd
24 if a.dp > 0 {
25 n += a.dp
26 }
27 if a.dp < 0 {
28 n += -a.dp
29 }
30
31 buf := make([]byte, n)
32 w := 0
33 switch {
34 case a.nd == 0:
35 return "0"
36
37 case a.dp <= 0:
38 // zeros fill space between decimal point and digits
39 buf[w] = '0'
40 w++
41 buf[w] = '.'
42 w++
43 w += digitZero(buf[w : w+-a.dp])
44 w += copy(buf[w:], a.d[0:a.nd])
45
46 case a.dp < a.nd:
47 // decimal point in middle of digits
48 w += copy(buf[w:], a.d[0:a.dp])
49 buf[w] = '.'
50 w++
51 w += copy(buf[w:], a.d[a.dp:a.nd])
52
53 default:
54 // zeros fill space between digits and decimal point
55 w += copy(buf[w:], a.d[0:a.nd])
56 w += digitZero(buf[w : w+a.dp-a.nd])
57 }
58 return string(buf[0:w])
59}
60
61func digitZero(dst []byte) int {
62 for i := range dst {

Callers

nothing calls this directly

Calls 1

digitZeroFunction · 0.70

Tested by

no test coverage detected