Skip to content
This repository has been archived by the owner on Oct 23, 2024. It is now read-only.

Commit

Permalink
bug fixed for float parse. for issue #1723
Browse files Browse the repository at this point in the history
  • Loading branch information
wenshao committed Feb 18, 2018
1 parent deb20c7 commit ab9cfc2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/main/java/com/alibaba/fastjson/parser/JSONLexerBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -2472,7 +2472,7 @@ public final float scanFieldFloat(char[] fieldName) {
count = bp + offset - start - 1;
}

if (!exp && count < 18) {
if ((!exp) && count < 17) {
value = ((float) intVal) / power;
if (negative) {
value = -value;
Expand Down Expand Up @@ -2652,7 +2652,7 @@ public final float scanFloat(char seperator) {
count = bp + offset - start - 1;
}

if (!exp && count < 20) {
if ((!exp) && count < 17) {
value = ((float) intVal) / power;
if (negative) {
value = -value;
Expand Down
13 changes: 12 additions & 1 deletion src/test/java/com/alibaba/json/bvt/issue_1700/Issue1723.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,23 @@
package com.alibaba.json.bvt.issue_1700;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.parser.Feature;
import junit.framework.TestCase;

public class Issue1723 extends TestCase {
public void test_for_issue() throws Exception {
User user = JSON.parseObject("{\"age\":\"0.9390308260917664\"}", User.class);
assertEquals(0.9390308F, user.age);
assertEquals(0.9390308260917664F, user.age);
}

public void test_for_issue_1() throws Exception {
User user = JSON.parseObject("{\"age\":\"8.200000000000001\"}", User.class);
assertEquals(8.200000000000001F, user.age);
}

public void test_for_issue_2() throws Exception {
User user = JSON.parseObject("[\"8.200000000000001\"]", User.class, Feature.SupportArrayToBean);
assertEquals(8.200000000000001F, user.age);
}

public static class User {
Expand Down

0 comments on commit ab9cfc2

Please sign in to comment.