Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

去掉BigDecimal多余的0 #4486

Open
dong618 opened this issue Mar 9, 2024 · 2 comments
Open

去掉BigDecimal多余的0 #4486

dong618 opened this issue Mar 9, 2024 · 2 comments

Comments

@dong618
Copy link

dong618 commented Mar 9, 2024

希望num2类型的数值在转json的时候可以类似num3直接去掉后面多余的0

public void testJson() {
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("num1",12.1000);
        jsonObject.put("num2",new BigDecimal("12.1000"));
        jsonObject.put("num3",new BigDecimal("12.1000").stripTrailingZeros());
        System.err.println(JSON.toJSONString(jsonObject, JSONWriter.Feature.WriteNonStringValueAsString,
                JSONWriter.Feature.WriteNullListAsEmpty,
                JSONWriter.Feature.WriteMapNullValue,
                JSONWriter.Feature.WriteNullNumberAsZero,
                JSONWriter.Feature.WriteBigDecimalAsPlain));
    }

目前输出结果:{"num1":"12.1","num2":"12.1000","num3":"12.1"}
期望结果:{"num1":"12.1","num2":"12.1","num3":"12.1"}

swapdewalkar added a commit to swapdewalkar/fastjson that referenced this issue Mar 26, 2024
@swapdewalkar
Copy link

Create a PR for this

@mysmlz
Copy link

mysmlz commented May 7, 2024

去掉WriteBigDecimalAsPlain试试?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants