保留兩位小數:資料庫欄位型別NUMBER,Java欄位型別Double型別

ZHOU_VIP發表於2017-03-20

1.資料庫欄位型別


查出的資料小數點後帶兩位小數


2.後臺查出的json卻沒有兩位小數


[{
		recordId : 20170320142740038015948,
		appSysId : 23551,
		appDeptId : 3,
		orgDeptName : null,
		carHostNO : 1019,
		secureNo : 111,
		secureStartTime : 2017 - 03 - 21,
		secureEndTime : 2017 - 03 - 22,
		secureHandle : xxx,
		secureInform : null,
		vehicleModel : null,
		securePay : 11122,
		secureAccNo : 222,
		secureAccPay : 22233.0,
		secureTax : 111.0,
		secureRemark : sdadada,
		secureNum : 33466.0,
		extraMap : null
	}, null, null, null, null, null, null, null, null, null]

因為:


CarSecureListResp中這幾個欄位都是Double型別


3.修改程式碼:

這幾個幾個欄位格式化帶.00,再在CarSecureListResp加在幾個欄位用於存放格式化過的值



4.最後查出的json


{
    "retCode":1,
    "retMsg":"操作成功",
    "list":[
        {
            "recordId":"20170320162514963019983",
            "appSysId":2009,
            "appDeptId":2,
            "orgDeptName":"鹽城供電公司_響水供電公司",
            "carHostNO":"蘇JF6772",
            "secureNo":"AAA",
            "secureStartTime":"2016-11-01",
            "secureEndTime":"2016-11-02",
            "secureHandle":"啊哈哈的",
            "securePay":102,
            "securePayStr":"102.00",
            "secureAccNo":"BBB",
            "secureAccPay":156,
            "secureAccPayStr":"156.00",
            "secureTax":452,
            "secureTaxStr":"452.00",
            "secureRemark":"黃磊1",
            "secureNum":710,
            "secureNumStr":"710.00"
        },
        {
            "recordId":"20170320145248466019516",
            "appSysId":2009,
            "appDeptId":2,
            "orgDeptName":"鹽城供電公司_響水供電公司",
            "carHostNO":"蘇JF6772",
            "secureNo":"AAAA",
            "secureStartTime":"2017-01-01",
            "secureEndTime":"2017-02-01",
            "secureHandle":"張三88",
            "securePay":1000,
            "securePayStr":"1000.00",
            "secureAccNo":"CCCC",
            "secureAccPay":550.1,
            "secureAccPayStr":"550.10",
            "secureTax":120,
            "secureTaxStr":"120.00",
            "secureRemark":"啊哈哈",
            "secureNum":1670.1,
            "secureNumStr":"1670.10"
        },
        {
            "recordId":"20170320145248968014513",
            "appSysId":2009,
            "appDeptId":2,
            "orgDeptName":"鹽城供電公司_響水供電公司",
            "carHostNO":"蘇JF6772",
            "secureNo":"BBBB",
            "secureStartTime":"2017-02-01",
            "secureEndTime":"2017-03-01",
            "secureHandle":"李四88",
            "securePay":2000,
            "securePayStr":"2000.00",
            "secureAccNo":"DDDD",
            "secureAccPay":650.22,
            "secureAccPayStr":"650.22",
            "secureTax":101,
            "secureTaxStr":"101.00",
            "secureRemark":"額呵呵",
            "secureNum":2751.22,
            "secureNumStr":"2751.22"
        },
        {
            "recordId":"20170320142740038015948",
            "appSysId":23551,
            "appDeptId":3,
            "orgDeptName":"警保部_人事處",
            "carHostNO":"1019",
            "secureNo":"111",
            "secureStartTime":"2017-03-21",
            "secureEndTime":"2017-03-22",
            "secureHandle":"xxx",
            "securePay":11122,
            "securePayStr":"11122.00",
            "secureAccNo":"222",
            "secureAccPay":22233,
            "secureAccPayStr":"22233.00",
            "secureTax":111,
            "secureTaxStr":"111.00",
            "secureRemark":"sdadada",
            "secureNum":33466,
            "secureNumStr":"33466.00"
        }
    ],
    "totalNum":4,
    "curRecordNum":4,
    "startRow":0,
    "nextStartRow":4
}

5.前臺可以取帶兩位小數的值,OK~~

參考:

http://blog.csdn.net/huaishuming/article/details/17752365

http://www.cnblogs.com/nayitian/p/3214178.html

相關文章