Skip to content

Commit

Permalink
Fix issue #160 by accounting for negative decimal part
Browse files Browse the repository at this point in the history
  • Loading branch information
larsga committed Nov 27, 2020
1 parent d60ecc0 commit 22a806e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,10 @@ else if (number.length() < 19)
long decimalPart = Long.parseLong(number.substring(endInteger + 1, endDecimal));
int digits = endDecimal - endInteger - 1;

// if intPart is negative we can't add a positive decimalPart to it
if (intPart < 0)
decimalPart = decimalPart * -1;

value = (decimalPart / Math.pow(10, digits)) + intPart;
pos = endDecimal;

Expand Down
10 changes: 10 additions & 0 deletions core/src/test/resources/function-tests.json
Original file line number Diff line number Diff line change
Expand Up @@ -782,6 +782,16 @@
"input" : "{}",
"output" : "124274772478237237823782728372873000000012347427427378238238283"
},
{
"query" : "number(\"-1.4\")",
"input" : "{}",
"output" : "-1.4"
},
{
"query" : "number(\"-2.513\")",
"input" : "{}",
"output" : "-2.513"
},
{
"input" : "{}",
"output" : "2",
Expand Down

0 comments on commit 22a806e

Please sign in to comment.