fastjson处理BigDecimal类型比如5.00 转json后变成了5,我想程序里保持我的原值该如何处理呢?
下面是一段测试代码:
List<TestVo> lists = Lists.newArrayList();
TestVo v1 = new TestVo();
v1.setId("1");
v1.setAmt1(2.00);
BigDecimal b = new BigDecimal(5.00);
v1.setAmt2(b);
TestVo v2 = new TestVo();
v2.setId("1");
v2.setAmt1(2.00);
BigDecimal b1 = new BigDecimal(5.00);
v2.setAmt2(b);
lists.add(v1);
lists.add(v2);
Map map = Maps.newHashMap();
map.put("data", lists);
System.out.println(JSON.toJSON(map));
{"data":[{"amt1":2.0,"amt2":5,"id":"1"},{"amt1":2.0,"amt2":5,"id":"1"}]}
1条答案
按热度按时间laawzig21#
new BigDecimal(5.00).toString()的结果就是"5"啊,new BigDecimal("5.00").toString()