Expose a Coefficient() function

This commit is contained in:
Chris Guiney 2017-01-16 14:54:52 -08:00
parent d6f52241f3
commit c1c27c221b
2 changed files with 13 additions and 0 deletions

View file

@ -332,6 +332,11 @@ func (d Decimal) Exponent() int32 {
return d.exp 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. // IntPart returns the integer component of the decimal.
func (d Decimal) IntPart() int64 { func (d Decimal) IntPart() int64 {
scaledD := d.rescale(0) scaledD := d.rescale(0)

View file

@ -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 type DecimalSlice []Decimal
func (p DecimalSlice) Len() int { return len(p) } func (p DecimalSlice) Len() int { return len(p) }