Fix overflow error for quantities stored as doubles. Closes #2244.
This commit is contained in:
parent
cc5498a42a
commit
1f708637b6
@ -61,7 +61,7 @@ public class WbQuantityExpr implements WbExpression<QuantityValue> {
|
||||
@Override
|
||||
public QuantityValue evaluate(ExpressionContext ctxt)
|
||||
throws SkipSchemaExpressionException {
|
||||
StringValue amount = getLanguageExpr().evaluate(ctxt);
|
||||
StringValue amount = getAmountExpr().evaluate(ctxt);
|
||||
// we know the amount is nonnull, nonempty here
|
||||
|
||||
BigDecimal parsedAmount = null;
|
||||
@ -99,7 +99,7 @@ public class WbQuantityExpr implements WbExpression<QuantityValue> {
|
||||
}
|
||||
|
||||
@JsonProperty("amount")
|
||||
public WbExpression<? extends StringValue> getLanguageExpr() {
|
||||
public WbExpression<? extends StringValue> getAmountExpr() {
|
||||
return amountExpr;
|
||||
}
|
||||
|
||||
|
@ -59,7 +59,7 @@ public class WbStringVariable extends WbVariableExpr<StringValue> {
|
||||
if (!cell.value.toString().isEmpty()) {
|
||||
String stringValue = cell.value.toString();
|
||||
if (cell.value instanceof Double && ((Double)cell.value) % 1 == 0) {
|
||||
stringValue = Integer.toString(((Double)cell.value).intValue());
|
||||
stringValue = Long.toString(((Double)cell.value).longValue());
|
||||
}
|
||||
return Datamodel.makeStringValue(stringValue.trim());
|
||||
}
|
||||
|
@ -47,6 +47,12 @@ public class WbQuantityExprTest extends WbExpressionTest<QuantityValue> {
|
||||
evaluatesTo(Datamodel.makeQuantityValue(new BigDecimal("4.00"), null, null, "1"), exprWithoutUnit);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOverflow() {
|
||||
setRow(14341937500d);
|
||||
evaluatesTo(Datamodel.makeQuantityValue(new BigDecimal("14341937500"), null, null, "1"), exprWithoutUnit);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInvalidAmountWithoutUnit() {
|
||||
setRow("hello");
|
||||
|
@ -70,6 +70,22 @@ public class WbStringVariableTest extends WbVariableTest<StringValue> {
|
||||
evaluatesTo(Datamodel.makeStringValue("45"), new Cell(45.0,null));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that large doubles are correctly converted to strings
|
||||
*/
|
||||
@Test
|
||||
public void testLargeDouble() {
|
||||
evaluatesTo(Datamodel.makeStringValue("14341937500"), new Cell(14341937500d, null));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that large doubles are correctly converted to strings
|
||||
*/
|
||||
@Test
|
||||
public void testLong() {
|
||||
evaluatesTo(Datamodel.makeStringValue("14341937500"), new Cell(14341937500L, null));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testLeadingWhitespace() {
|
||||
|
Loading…
Reference in New Issue
Block a user