func (a *decimal) RoundedInteger() uint64 {
	if a.dp > 20 {
		return 0xFFFFFFFFFFFFFFFF
	}
	var i int
	n := uint64(0)
	for i = 0; i < a.dp && i < a.nd; i++ {
		n = n*10 + uint64(a.d[i]-'0')
	}
	for ; i < a.dp; i++ {
		n *= 10
	}
	if shouldRoundUp(a, a.dp) {
		n++
	}
	return n
}
Extract integer part, rounded appropriately.
No guarantees about overflow.
package v1
type decimal struct {
	d     [800]byte  
	nd    int        
	dp    int        
	neg   bool
	trunc bool  
}
func (a *decimal) String() string {
	n := 10 + a.nd
	if a.dp > 0 {
		n += a.dp
	}
	if a.dp < 0 {
		n += -a.dp
	}
	buf := make([]byte, n)
	w := 0
	switch {
	case a.nd == 0:
		return "0"
	case a.dp <= 0:
		buf[w] = '0'
		w++
		buf[w] = '.'
		w++
		w += digitZero(buf[w : w+-a.dp])
		w += copy(buf[w:], a.d[0:a.nd])
	case a.dp < a.nd:
		w += copy(buf[w:], a.d[0:a.dp])
		buf[w] = '.'
		w++
		w += copy(buf[w:], a.d[a.dp:a.nd])
	default:
		w += copy(buf[w:], a.d[0:a.nd])
		w += digitZero(buf[w : w+a.dp-a.nd])
	}
	return string(buf[0:w])
}
func digitZero(dst []byte) int {
	for i := range dst {
		dst[i] = '0'
	}
	return len(dst)
}
func trim(a *decimal) {
	for a.nd > 0 && a.d[a.nd-1] == '0' {
		a.nd--
	}
	if a.nd == 0 {
		a.dp = 0
	}
}
func (a *decimal) Assign(v uint64) {
	var buf [24]byte
	n := 0
	for v > 0 {
		v1 := v / 10
		v -= 10 * v1
		buf[n] = byte(v + '0')
		n++
		v = v1
	}
	a.nd = 0
	for n--; n >= 0; n-- {
		a.d[a.nd] = buf[n]
		a.nd++
	}
	a.dp = a.nd
	trim(a)
}
const maxShift = 27
func rightShift(a *decimal, k uint) {
	r := 0  
	w := 0  
	n := 0
	for ; n>>k == 0; r++ {
		if r >= a.nd {
			if n == 0 {
				a.nd = 0
				return
			}
			for n>>k == 0 {
				n = n * 10
				r++
			}
			break
		}
		c := int(a.d[r])
		n = n*10 + c - '0'
	}
	a.dp -= r - 1
	for ; r < a.nd; r++ {
		c := int(a.d[r])
		dig := n >> k
		n -= dig << k
		a.d[w] = byte(dig + '0')
		w++
		n = n*10 + c - '0'
	}
	for n > 0 {
		dig := n >> k
		n -= dig << k
		if w < len(a.d) {
			a.d[w] = byte(dig + '0')
			w++
		} else if dig > 0 {
			a.trunc = true
		}
		n = n * 10
	}
	a.nd = w
	trim(a)
}
type leftCheat struct {
	delta  int     
	cutoff string  
}
var leftcheats = []leftCheat{
	{0, ""},
	{1, "5"},                    
	{1, "25"},                   
	{1, "125"},                  
	{2, "625"},                  
	{2, "3125"},                 
	{2, "15625"},                
	{3, "78125"},                
	{3, "390625"},               
	{3, "1953125"},              
	{4, "9765625"},              
	{4, "48828125"},             
	{4, "244140625"},            
	{4, "1220703125"},           
	{5, "6103515625"},           
	{5, "30517578125"},          
	{5, "152587890625"},         
	{6, "762939453125"},         
	{6, "3814697265625"},        
	{6, "19073486328125"},       
	{7, "95367431640625"},       
	{7, "476837158203125"},      
	{7, "2384185791015625"},     
	{7, "11920928955078125"},    
	{8, "59604644775390625"},    
	{8, "298023223876953125"},   
	{8, "1490116119384765625"},  
	{9, "7450580596923828125"},  
}
func prefixIsLessThan(b []byte, s string) bool {
	for i := 0; i < len(s); i++ {
		if i >= len(b) {
			return true
		}
		if b[i] != s[i] {
			return b[i] < s[i]
		}
	}
	return false
}
func leftShift(a *decimal, k uint) {
	delta := leftcheats[k].delta
	if prefixIsLessThan(a.d[0:a.nd], leftcheats[k].cutoff) {
		delta--
	}
	r := a.nd          
	w := a.nd + delta  
	n := 0
	for r--; r >= 0; r-- {
		n += (int(a.d[r]) - '0') << k
		quo := n / 10
		rem := n - 10*quo
		w--
		if w < len(a.d) {
			a.d[w] = byte(rem + '0')
		} else if rem != 0 {
			a.trunc = true
		}
		n = quo
	}
	for n > 0 {
		quo := n / 10
		rem := n - 10*quo
		w--
		if w < len(a.d) {
			a.d[w] = byte(rem + '0')
		} else if rem != 0 {
			a.trunc = true
		}
		n = quo
	}
	a.nd += delta
	if a.nd >= len(a.d) {
		a.nd = len(a.d)
	}
	a.dp += delta
	trim(a)
}
func (a *decimal) Shift(k int) {
	switch {
	case a.nd == 0:
	case k > 0:
		for k > maxShift {
			leftShift(a, maxShift)
			k -= maxShift
		}
		leftShift(a, uint(k))
	case k < 0:
		for k < -maxShift {
			rightShift(a, maxShift)
			k += maxShift
		}
		rightShift(a, uint(-k))
	}
}
func shouldRoundUp(a *decimal, nd int) bool {
	if nd < 0 || nd >= a.nd {
		return false
	}
	if a.d[nd] == '5' && nd+1 == a.nd {  
		if a.trunc {
			return true
		}
		return nd > 0 && (a.d[nd-1]-'0')%2 != 0
	}
	return a.d[nd] >= '5'
}
func (a *decimal) Round(nd int) {
	if nd < 0 || nd >= a.nd {
		return
	}
	if shouldRoundUp(a, nd) {
		a.RoundUp(nd)
	} else {
		a.RoundDown(nd)
	}
}
func (a *decimal) RoundDown(nd int) {
	if nd < 0 || nd >= a.nd {
		return
	}
	a.nd = nd
	trim(a)
}
func (a *decimal) RoundUp(nd int) {
	if nd < 0 || nd >= a.nd {
		return
	}
	for i := nd - 1; i >= 0; i-- {
		c := a.d[i]
		if c < '9' {  
			a.d[i]++
			a.nd = i + 1
			return
		}
	}
	a.d[0] = '1'
	a.nd = 1
	a.dp++
}