func (d Decimal64) Append(buf []byte, format byte, prec int) []byte {
	flav, sign, exp, significand := d.parts()
	if sign == 1 {
		buf = append(buf, '-')
	}
	switch flav {
	case flQNaN, flSNaN:
		return appendUint64(append(buf, []byte("NaN")...), significand, 10000)
	case flInf:
		return append(buf, []byte("inf")...)
	}
formatBlock:
	switch format {
	case 'e', 'E':
		whole := significand / decimal64Base
		buf = append(buf, byte('0'+whole))
		frac := significand - decimal64Base*whole
		if frac > 0 {
			buf = appendFrac64(append(buf, '.'), frac, decimal64Base/10)
		}
		exp += 15
		if exp != 0 {
			buf = append(buf, format)
			if exp < 0 {
				buf = append(buf, '-')
				exp = -exp
			} else {
				buf = append(buf, '+')
			}
			buf = appendUint64(buf, uint64(exp), 1000)
		}
		return buf
	case 'f', 'F':
		exponent, whole, frac := expWholeFrac(exp, significand)
		if whole > 0 {
			buf = appendUint64(buf, whole, decimal64Base)
			for ; exponent > 0; exponent-- {
				buf = append(buf, '0')
			}
		} else {
			buf = append(buf, '0')
		}
		if frac > 0 {
			buf = appendFrac64(append(buf, '.'), frac, decimal64Base)
		}
		return buf
	case 'g', 'G':
		if exp < -16-4 || exp > prec {
			format -= 'g' - 'e'
		} else {
			format -= 'g' - 'f'
		}
		goto formatBlock
	default:
		return append(buf, '%', format)
	}
}
Append appends the text representation of d to buf.
package decimal
import (
	"fmt"
)
func appendFrac64(buf []byte, n, limit uint64) []byte {
	for n > 0 {
		msd := n / limit
		buf = append(buf, byte('0'+msd))
		n -= limit * msd
		limit /= 10
	}
	return buf
}
func appendUint64(buf []byte, n, limit uint64) []byte {
	zeroPrefix := false
	for limit > 0 {
		msd := n / limit
		if msd > 0 || zeroPrefix {
			buf = append(buf, byte('0'+msd))
			zeroPrefix = true
		}
		n -= limit * msd
		limit /= 10
	}
	return buf
}