Skip to content

Commit fa1c850

Browse files
committed
Display float/double values in an appropriate format
1 parent 7559aa9 commit fa1c850

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

msgpack-core/src/main/java/org/msgpack/value/holder/FloatHolder.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,14 @@ public int hashCode() {
165165

166166
@Override
167167
public String toString() {
168-
return Double.toString(value);
168+
switch(tpe) {
169+
case FLOAT:
170+
return Float.toString((float) value);
171+
case DOUBLE:
172+
return Double.toString(value);
173+
default:
174+
throw new IllegalStateException("cannto reach here");
175+
}
169176
}
170177

171178

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package org.msgpack.value.holder
2+
3+
import org.msgpack.core.MessagePackSpec
4+
5+
/**
6+
*
7+
*/
8+
class FloatHolderTest extends MessagePackSpec {
9+
10+
"FloatHolder" should {
11+
12+
"display value in an appropriate format" in {
13+
14+
val h = new FloatHolder
15+
val f = 0.1341f
16+
h.setFloat(f)
17+
h.toString shouldBe java.lang.Float.toString(f)
18+
19+
val d = 0.1341341344
20+
h.setDouble(d)
21+
h.toString shouldBe java.lang.Double.toString(d)
22+
}
23+
24+
}
25+
26+
}

0 commit comments

Comments
 (0)