func (d Decimal) Div(y Decimal, scale int) Decimal {
	if d.scale > y.scale+scale {
		y = y.ToScale(d.scale - scale)
	} else {
		d = d.ToScale(y.scale + scale)
	}
	return New(new(big.Int).Div(bigIntDefault(d.i), bigIntDefault(y.i)), scale)
}
Div divides d by y and returns the result in the provided scale. If the
provided scale is too small for the result of d/y, the result is truncated
towards 0. d is left unchanged.
package decimal
import (
	"errors"
	"fmt"
	"math"
	"math/big"
	"strings"
)
type Decimal struct {
	i     *big.Int
	scale int
}
func New(i *big.Int, scale int) Decimal {
	return Decimal{
		i:     i,
		scale: scale,
	}
}
func NewFromInt64(i int64) Decimal {
	return New(big.NewInt(i), 0)
}
func NewFromFloat64(f float64, scale int) Decimal {
	i := big.NewInt(int64(f * math.Pow(float64(10), float64(scale))))
	return New(i, scale)
}
var ErrUnsupportedDecimalNotation = errors.New("luno: unsupported decimal notation")
func NewFromString(s string) (Decimal, error) {
	if strings.IndexByte(s, 'e') > -1 {
		return Decimal{}, ErrUnsupportedDecimalNotation
	}
	scale := getScale(s)
	s = strings.Replace(s, ".", "", 1)
	i, ok := new(big.Int).SetString(s, 10)
	if !ok {
		return Decimal{}, ErrUnsupportedDecimalNotation
	}
	return New(i, scale), nil
}
func Zero() Decimal {
	return New(big.NewInt(0), 0)
}
func (d Decimal) MarshalJSON() ([]byte, error) {
	return []byte(`"` + d.String() + `"`), nil
}
func (d *Decimal) UnmarshalJSON(b []byte) error {
	s := strings.Trim(string(b), `"`)
	y, err := NewFromString(s)
	if err != nil {
		return err
	}
	*d = y
	return nil
}
// Strings returns a string representation of d.
func (d Decimal) String() string {
	di := bigIntDefault(d.i)
	s := di.String()
	var sign string
	if di.Sign() < 0 {
		sign = "-"
		s = strings.TrimPrefix(s, "-")
	}
	if d.scale > 0 {
		scale := int(d.scale)
		if len(s) < scale+1 {
			pad := scale + 1 - len(s)
			s = strings.Repeat("0", pad) + s
		}
		return fmt.Sprintf("%s%s.%s", sign, s[:len(s)-scale], s[len(s)-scale:])
	} else if d.scale < 0 {
		return sign + s + strings.Repeat("0", -int(d.scale))
	}
	return sign + s
}
func (d Decimal) QueryValue() string {
	return d.String()
}
func (d Decimal) Float64() float64 {
	return float64(d.i.Int64()) * math.Pow(float64(10), float64(-d.scale))
}
func (d Decimal) ToScale(scale int) Decimal {
	exponent := d.scale - scale
	if exponent < 0 {
		exponent = -exponent
	}
	s := new(big.Int)
	s.Exp(big.NewInt(10), big.NewInt(int64(exponent)), nil)
	di := bigIntDefault(d.i)
	o := new(big.Int)
	if d.scale > scale {
		o.Quo(di, s)
	} else {
		o.Mul(di, s)
	}
	return Decimal{i: o, scale: scale}
}
func (d Decimal) Sign() int {
	return bigIntDefault(d.i).Sign()
}
func (d Decimal) Cmp(y Decimal) int {
	var _d, _y = scaleToMax(d, y)
	di := bigIntDefault(_d.i)
	yi := bigIntDefault(_y.i)
	return di.Cmp(yi)
}
func (d Decimal) Neg() Decimal {
	return Decimal{
		i:     new(big.Int).Neg(bigIntDefault(d.i)),
		scale: d.scale,
	}
}
func (d Decimal) Add(y Decimal) Decimal {
	var _d, _y = scaleToMax(d, y)
	di := bigIntDefault(_d.i)
	yi := bigIntDefault(_y.i)
	return New(new(big.Int).Add(di, yi), _d.scale)
}
func (d Decimal) Sub(y Decimal) Decimal {
	var _d, _y = scaleToMax(d, y)
	di := bigIntDefault(_d.i)
	yi := bigIntDefault(_y.i)
	return New(new(big.Int).Sub(di, yi), _d.scale)
}
func (d Decimal) MulInt64(y int64) Decimal {
	di := bigIntDefault(d.i)
	return New(new(big.Int).Mul(di, big.NewInt(y)), d.scale)
}
func (d Decimal) DivInt64(y int64) Decimal {
	di := bigIntDefault(d.i)
	return New(new(big.Int).Div(di, big.NewInt(y)), d.scale)
}
func (d Decimal) Mul(y Decimal) Decimal {
	di := bigIntDefault(d.i)
	yi := bigIntDefault(y.i)
	return New(new(big.Int).Mul(di, yi), d.scale+y.scale)
}