diff --git a/decimal.go b/decimal.go index 91f9f6c..40edfd3 100644 --- a/decimal.go +++ b/decimal.go @@ -332,6 +332,11 @@ 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 { + return d.value +} + // IntPart returns the integer component of the decimal. func (d Decimal) IntPart() int64 { scaledD := d.rescale(0) diff --git a/decimal_test.go b/decimal_test.go index b0b2088..c5c9d2f 100644 --- a/decimal_test.go +++ b/decimal_test.go @@ -1044,6 +1044,14 @@ func didPanic(f func()) bool { } +func TestDecimal_Coefficient(t *testing.T) { + d := New(123, 0) + co := d.Coefficient() + if co.Int64() != 123 { + t.Error("Coefficient should be 123; Got:", co) + } +} + type DecimalSlice []Decimal func (p DecimalSlice) Len() int { return len(p) }