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

v1.2.40 反序列化float field,当field精度超过float的精度范围,结果出现负数 #1723

Closed
KaneWu0 opened this issue Jan 25, 2018 · 2 comments
Labels
Milestone

Comments

@KaneWu0
Copy link

KaneWu0 commented Jan 25, 2018

// Bean 对象
 public class User {
    private float age;
    public float getAge() {
        return age;
    }
    public void setAge(float age) {
        this.age = age;
    }
    @Override
    public String toString() {
        return "User{" +
                "age=" + age +
                '}';
    }
}
// 反序列化代码
User user = JSON.parseObject("{\"age\":\"0.9390308260917664\"}", User.class);
 System.out.println(user);

结果:
期望结果是:User{age=0.9390308}
实际结果是:User{age=-1.1075817}

@wenshao wenshao added the bug label Feb 1, 2018
@wenshao wenshao added this to the 1.2.46 milestone Feb 1, 2018
wenshao added a commit that referenced this issue Feb 1, 2018
@d4ksn
Copy link

d4ksn commented Feb 14, 2018

@wenshao
不好意思,升级到1.2.46,还是有一些case有问题,比如下面这个:
User user = JSON.parseObject("{\"age\":8.200000000000001}", User.class);

@wenshao wenshao modified the milestones: 1.2.46, 1.2.47 Feb 18, 2018
@wenshao
Copy link
Member

wenshao commented Mar 15, 2018

https://github.com/alibaba/fastjson/releases/tag/1.2.47
问题已修复,请用新版本

@wenshao wenshao closed this as completed Mar 15, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants