()
| 578 | } |
| 579 | |
| 580 | func (a *decimal) String() string { |
| 581 | n := 10 + a.nd |
| 582 | if a.dp > 0 { |
| 583 | n += a.dp |
| 584 | } |
| 585 | if a.dp < 0 { |
| 586 | n += -a.dp |
| 587 | } |
| 588 | |
| 589 | buf := make([]byte, n) |
| 590 | w := 0 |
| 591 | switch { |
| 592 | case a.nd == 0: |
| 593 | return "0" |
| 594 | |
| 595 | case a.dp <= 0: |
| 596 | // zeros fill space between decimal point and digits |
| 597 | buf[w] = '0' |
| 598 | w++ |
| 599 | buf[w] = '.' |
| 600 | w++ |
| 601 | w += digitZero(buf[w : w+-a.dp]) |
| 602 | w += copy(buf[w:], a.d[0:a.nd]) |
| 603 | |
| 604 | case a.dp < a.nd: |
| 605 | // decimal point in middle of digits |
| 606 | w += copy(buf[w:], a.d[0:a.dp]) |
| 607 | buf[w] = '.' |
| 608 | w++ |
| 609 | w += copy(buf[w:], a.d[a.dp:a.nd]) |
| 610 | |
| 611 | default: |
| 612 | // zeros fill space between digits and decimal point |
| 613 | w += copy(buf[w:], a.d[0:a.nd]) |
| 614 | w += digitZero(buf[w : w+a.dp-a.nd]) |
| 615 | } |
| 616 | return string(buf[0:w]) |
| 617 | } |
| 618 | |
| 619 | func digitZero(dst []byte) int { |
| 620 | for i := range dst { |
nothing calls this directly
no test coverage detected