()
| 20 | } |
| 21 | |
| 22 | func (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 | |
| 61 | func digitZero(dst []byte) int { |
| 62 | for i := range dst { |
nothing calls this directly
no test coverage detected