mirror of
https://github.com/shopspring/decimal.git
synced 2024-11-22 20:40:48 +01:00
Merge pull request #42 from chrisguiney/expose-coefficient
Expose a Coefficient() function
This commit is contained in:
commit
de8af6d48f
2 changed files with 13 additions and 0 deletions
|
@ -418,6 +418,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)
|
||||||
|
|
|
@ -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
|
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