Skip to content
Permalink
Browse files
Merge pull request #12 from CrazyHZM/floatBug, fix float accuracy issues
  • Loading branch information
chickenlj committed Nov 17, 2019
2 parents 6a0cd3c + a8cb0b2 commit 6d112471d5aef0b952fa5f0a62bf97e5a52e16f0
Showing 2 changed files with 10 additions and 0 deletions.
@@ -106,6 +106,8 @@ public void writeObject(Object obj, AbstractHessianOutput out)
break;

case FLOAT:
out.writeDouble(Double.parseDouble(String.valueOf(((Number) obj).floatValue())));
break;
case DOUBLE:
out.writeDouble(((Number) obj).doubleValue());
break;
@@ -83,4 +83,12 @@ public void testGetGrandsonUserName() throws Exception {
Assert.assertEquals("tom", serializedUser.getUserName());
}

@Test
public void testFloat() throws Exception {
Float fData = 99.8F;
Double dData = 99.8D;
Assert.assertEquals(dData, baseHessianSerialize(fData));
Assert.assertEquals(dData, baseHessian2Serialize(fData));
}

}

0 comments on commit 6d11247

Please sign in to comment.