Fix decimaltype float constructor

This commit is contained in:
James Agnew 2016-06-20 10:52:23 -04:00
parent 1683cf8cef
commit 102548d22c
3 changed files with 38 additions and 4 deletions

View File

@ -74,7 +74,7 @@ public class DecimalType extends PrimitiveType<BigDecimal> implements Comparable
* Constructor
*/
public DecimalType(long theValue) {
setValue(new BigDecimal(theValue));
setValue(theValue);
}
/**
@ -148,21 +148,21 @@ public class DecimalType extends PrimitiveType<BigDecimal> implements Comparable
* Sets a new value using an integer
*/
public void setValueAsInteger(int theValue) {
setValue(new BigDecimal(theValue));
setValue(BigDecimal.valueOf(theValue));
}
/**
* Sets a new value using a long
*/
public void setValue(long theValue) {
setValue(new BigDecimal(theValue));
setValue(BigDecimal.valueOf(theValue));
}
/**
* Sets a new value using a double
*/
public void setValue(double theValue) {
setValue(new BigDecimal(theValue));
setValue(BigDecimal.valueOf(theValue));
}
@Override

View File

@ -0,0 +1,29 @@
package ca.uhn.fhir.model;
import static org.junit.Assert.*;
import org.hl7.fhir.dstu3.model.DecimalType;
import org.junit.Test;
public class DecimalTypeTest {
@Test
public void testDoubleValue() {
DecimalType d = new DecimalType(1.2D);
assertEquals("1.2", d.getValueAsString());
d = new DecimalType();
d.setValue(1.2D);
assertEquals("1.2", d.getValueAsString());
d = new DecimalType();
d.setValue(10);
assertEquals("10", d.getValueAsString());
d = new DecimalType();
d.setValue(10L);
assertEquals("10", d.getValueAsString());
}
}

View File

@ -359,6 +359,11 @@
Server now supports the _at parameter (including multiple repetitions)
for history operation
</action>
<action type="fix">
DecimalType used BigDecimal constructor instead of valueOf method to
create a BigDecimal from a double, resulting in weird floating point
conversions. Thanks to Craig McClendon for reporting!
</action>
</release>
<release version="1.5" date="2016-04-20">
<action type="fix" issue="339">