Skip to content

Commit 23f3464

Browse files
committed
bug fixed for double
1 parent fbaf184 commit 23f3464

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

src/main/java/com/alibaba/fastjson/JSONArray.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ public double getDoubleValue(int index) {
314314
return 0D;
315315
}
316316

317-
return castToDouble(value).floatValue();
317+
return castToDouble(value).doubleValue();
318318
}
319319

320320
public BigDecimal getBigDecimal(int index) {

src/main/java/com/alibaba/fastjson/JSONObject.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ public double getDoubleValue(String key) {
247247
return 0D;
248248
}
249249

250-
return castToDouble(value).floatValue();
250+
return castToDouble(value).doubleValue();
251251
}
252252

253253
public BigDecimal getBigDecimal(String key) {
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.alibaba.json.bvt.bug;
2+
3+
import junit.framework.Assert;
4+
import junit.framework.TestCase;
5+
6+
import com.alibaba.fastjson.JSON;
7+
import com.alibaba.fastjson.JSONArray;
8+
import com.alibaba.fastjson.JSONObject;
9+
10+
11+
public class Bug_for_jiangwei1 extends TestCase {
12+
public void test_double() throws Exception {
13+
JSONObject json = JSON.parseObject("{\"val\":12.3}");
14+
Assert.assertEquals(12.3D, json.getDoubleValue("val"));
15+
}
16+
17+
public void test_JSONArray_double() throws Exception {
18+
JSONArray json = JSON.parseArray("[12.3]");
19+
Assert.assertEquals(12.3D, json.getDoubleValue(0));
20+
}
21+
}

0 commit comments

Comments
 (0)