json格式化为何会将.00或.0以及.10尾部的0自动去掉?如何处理这种问题?

诠释这低调 发布于 2016/05/04 22:12
阅读 1K+
收藏 0
如何处理以下json出现的问题
期望输出:
[{ 
  "firstName": "Brett1",
  "lastName":"McLaughlin1", 
  "email": "aaaa1",
  "money": 100
},{ 
  "firstName": "Brett2",
  "lastName":"McLaughlin2", 
  "email": "aaaa3",
  "money": 400.10
}{ 
  "firstName": "Brett4",
  "lastName":"McLaughlin4", 
  "email": "aaaa14" ,
  "money": 300.02
}{ 
  "firstName": "Brett5",
  "lastName":"McLaughlin5", 
  "email": "aaaa5" ,
  "money": 200
}]

实际输出:
[{ 
  "firstName": "Brett1",
  "lastName":"McLaughlin1", 
  "email": "aaaa1",
  "money": 100.00
},{ 
  "firstName": "Brett2",
  "lastName":"McLaughlin2", 
  "email": "aaaa3",
  "money": 400.1
}{ 
  "firstName": "Brett4",
  "lastName":"McLaughlin4", 
  "email": "aaaa14" ,
  "money": 300.02
}{ 
  "firstName": "Brett5",
  "lastName":"McLaughlin5", 
  "email": "aaaa5" ,
  "money": 200
}]



加载中
1
agateriver
agateriver
对于数值类型来说,小数点后部分末尾的0本来就是多余,因为数值类型存储时无法保存小数部分末尾的无意义的0。除非你在输出时将其格式化成指定位数的小数位(实际上是以字符串输出)或者干脆将money用字符串存储。
0
求是科技
求是科技
很明显的问题哇,money对应的实体应该是String类型,同时这个字段在数据库应该是varchar
返回顶部
顶部