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

反序列化float精度超出会出现问题 #1944

@dengchengchao

Description

@dengchengchao

在反序列化的时候,如果数据类型是一个float类型,而对应的值超过了float类型很多的话,反序列化会出现很奇怪的数字。
代码如下:

    public static void main(String[] args) {
        String json="{\"num\":90.82195113}";
        Num num= JSONObject.parseObject(json,Num.class);
        System.out.println(num.getNum());
    }


    public static class Num {
        private float num;

        public float getNum() {
            return num;
        }

        public void setNum(float num) {
            this.num = num;
        }
    }

输出结果如下:

4.922605

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions