diff --git a/decimal.go b/decimal.go index 8014910..6f7c41e 100644 --- a/decimal.go +++ b/decimal.go @@ -928,6 +928,7 @@ func (d Decimal) Ln(precision int32) (Decimal, error) { // NumDigits returns the number of digits of the decimal coefficient (d.Value) // Note: Current implementation is extremely slow for large decimals and/or decimals with large fractional part func (d Decimal) NumDigits() int { + d.ensureInitialized() // Note(mwoss): It can be optimized, unnecessary cast of big.Int to string if d.IsNegative() { return len(d.value.String()) - 1 diff --git a/decimal_test.go b/decimal_test.go index 2df9591..7dc5be6 100644 --- a/decimal_test.go +++ b/decimal_test.go @@ -2829,6 +2829,7 @@ func TestDecimal_NumDigits(t *testing.T) { {"-5.26", 3}, {"-5.2663117716", 11}, {"-26.1", 3}, + {"", 1}, } { d, _ := NewFromString(testCase.Dec)