Skip to content

Commit

Permalink
bug fixed for parseFloat/parseDouble, for issue #1944
Browse files Browse the repository at this point in the history
  • Loading branch information
wenshao committed Jul 6, 2018
1 parent 1180771 commit a1bf53b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/main/java/com/alibaba/fastjson/parser/JSONLexerBase.java
Expand Up @@ -2408,7 +2408,7 @@ public final float scanFieldFloat(char[] fieldName) {


float value; float value;
if (chLocal >= '0' && chLocal <= '9') { if (chLocal >= '0' && chLocal <= '9') {
int intVal = chLocal - '0'; long intVal = chLocal - '0';
for (;;) { for (;;) {
chLocal = charAt(bp + (offset++)); chLocal = charAt(bp + (offset++));
if (chLocal >= '0' && chLocal <= '9') { if (chLocal >= '0' && chLocal <= '9') {
Expand Down Expand Up @@ -2473,7 +2473,7 @@ public final float scanFieldFloat(char[] fieldName) {
} }


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


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


if (!exp && count < 20) { if (!exp && count < 17) {
value = ((double) intVal) / power; value = ((double) intVal) / power;
if (negative) { if (negative) {
value = -value; value = -value;
Expand Down Expand Up @@ -3427,7 +3427,7 @@ public final double scanFieldDouble(char[] fieldName) {
count = bp + offset - start - 1; count = bp + offset - start - 1;
} }


if (!exp && count < 20) { if (!exp && count < 17) {
value = ((double) intVal) / power; value = ((double) intVal) / power;
if (negative) { if (negative) {
value = -value; value = -value;
Expand Down
14 changes: 14 additions & 0 deletions src/test/java/com/alibaba/json/bvt/issue_1900/Issue1944.java
@@ -0,0 +1,14 @@
package com.alibaba.json.bvt.issue_1900;

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

public class Issue1944 extends TestCase {
public void test_for_issue() throws Exception {
assertEquals(90.82195113f, JSON.parseObject("{\"value\":90.82195113}", Model.class).value);
}

public static class Model {
public float value;
}
}

0 comments on commit a1bf53b

Please sign in to comment.