Merge pull request #42 from chrisguiney/expose-coefficient

Expose a Coefficient() function
This commit is contained in:
Victor Quinn 2017-02-15 17:39:50 -05:00 committed by GitHub
commit de8af6d48f
2 changed files with 13 additions and 0 deletions

View file

@ -418,6 +418,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)

View file

@ -1338,6 +1338,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) }