Fix decoding of .0

Since trailing 0 digits after the decimal point are trimmed, intString
becomes an empty string when there is no digit before the decimal point
and all digits after the decimal point is 0, causing big.Int SetString
to fail because there is no string to parse.

Fix #134.
This commit is contained in:
Ting-Wei Lan 2019-02-19 17:00:26 +08:00
parent cd690d0c9e
commit f39378d939
2 changed files with 5 additions and 0 deletions

View file

@ -130,6 +130,9 @@ func NewFromString(value string) (Decimal, error) {
// strip the insignificant digits for more accurate comparisons.
decimalPart := strings.TrimRight(parts[1], "0")
intString = parts[0] + decimalPart
if intString == "" && parts[1] != "" {
intString = "0"
}
expInt := -len(decimalPart)
exp += int64(expInt)
} else {

View file

@ -70,6 +70,8 @@ var testTableScientificNotation = map[string]string{
"1.2345E-1": "0.12345",
"0e5": "0",
"0e-5": "0",
"0.e0": "0",
".0e0": "0",
"123.456e0": "123.456",
"123.456e2": "12345.6",
"123.456e10": "1234560000000",