mirror of
https://github.com/shopspring/decimal.git
synced 2024-11-22 20:40:48 +01:00
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:
parent
cd690d0c9e
commit
f39378d939
2 changed files with 5 additions and 0 deletions
|
@ -130,6 +130,9 @@ func NewFromString(value string) (Decimal, error) {
|
||||||
// strip the insignificant digits for more accurate comparisons.
|
// strip the insignificant digits for more accurate comparisons.
|
||||||
decimalPart := strings.TrimRight(parts[1], "0")
|
decimalPart := strings.TrimRight(parts[1], "0")
|
||||||
intString = parts[0] + decimalPart
|
intString = parts[0] + decimalPart
|
||||||
|
if intString == "" && parts[1] != "" {
|
||||||
|
intString = "0"
|
||||||
|
}
|
||||||
expInt := -len(decimalPart)
|
expInt := -len(decimalPart)
|
||||||
exp += int64(expInt)
|
exp += int64(expInt)
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -70,6 +70,8 @@ var testTableScientificNotation = map[string]string{
|
||||||
"1.2345E-1": "0.12345",
|
"1.2345E-1": "0.12345",
|
||||||
"0e5": "0",
|
"0e5": "0",
|
||||||
"0e-5": "0",
|
"0e-5": "0",
|
||||||
|
"0.e0": "0",
|
||||||
|
".0e0": "0",
|
||||||
"123.456e0": "123.456",
|
"123.456e0": "123.456",
|
||||||
"123.456e2": "12345.6",
|
"123.456e2": "12345.6",
|
||||||
"123.456e10": "1234560000000",
|
"123.456e10": "1234560000000",
|
||||||
|
|
Loading…
Reference in a new issue