From c1c27c221bf1c6946e0e7678787aefb876aa5390 Mon Sep 17 00:00:00 2001 From: Chris Guiney Date: Mon, 16 Jan 2017 14:54:52 -0800 Subject: [PATCH] Expose a Coefficient() function --- decimal.go | 5 +++++ decimal_test.go | 8 ++++++++ 2 files changed, 13 insertions(+) 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) }