diff --git a/decimal.go b/decimal.go index 45bc3989..cb4bae3f 100644 --- a/decimal.go +++ b/decimal.go @@ -340,6 +340,14 @@ func (d Decimal) Exponent() int32 { return d.exp } +// Coefficient returns the coefficient of the decimal. It is scaled by 10^Exponent() +func (d Decimal) Coefficient() *big.Int { + // we copy the coefficient so that mutating the result does not mutate the + // Decimal. + return big.NewInt(0).Set(d.value) +} + + // IntPart returns the integer component of the decimal. func (d Decimal) IntPart() int64 { scaledD := d.rescale(0)