Added implementation of DigitsValue() that exposes the big.Int value part of the decimal.

This commit is contained in:
Gintautas Miliauskas 2016-01-22 13:02:50 +00:00
parent af95951b3f
commit 3b7679240e
2 changed files with 13 additions and 0 deletions

View file

@ -313,6 +313,12 @@ func (d Decimal) Equals(d2 Decimal) bool {
return d.Cmp(d2) == 0
}
// DigitsValue returns the integer that represents the digits of the decimal.
// This is the value of the decimal scaled by 10^Exponent().
func (d Decimal) DigitsValue() *big.Int {
return d.value
}
// Exponent returns the exponent, or scale component of the decimal.
func (d Decimal) Exponent() int32 {
return d.exp

View file

@ -885,6 +885,13 @@ func TestDecimal_Scale(t *testing.T) {
}
}
func TestDecimal_DigitsValue(t *testing.T) {
a := New(1234, -3)
if a.DigitsValue().Int64() != 1234 {
t.Errorf("error")
}
}
func TestDecimal_Abs1(t *testing.T) {
a := New(-1234, -4)
b := New(1234, -4)