mirror of
https://github.com/shopspring/decimal.git
synced 2024-11-22 20:40:48 +01:00
Expose a Coefficient() function
This commit is contained in:
parent
d6f52241f3
commit
c1c27c221b
2 changed files with 13 additions and 0 deletions
|
@ -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)
|
||||||
|
|
|
@ -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) }
|
||||||
|
|
Loading…
Reference in a new issue