我创建了onse序列化程序类,它应该将Bigdecimal限制为十进制后的两位数。但它也删除了零。例如:如果值为95.50,则截断零并在json中输出为95.5。
public class PriceJsonSerializer extends JsonSerializer {
@Override
public void serialize(BigDecimal value, JsonGenerator jgen,
SerializerProvider provider) throws IOException, JsonProcessingException
{
jgen.writeNumber(value.setScale(2,
BigDecimal.ROUND_HALF_UP).toString());
}
}
答案 0 :(得分:1)
要强制序列化器保留舍入而不将值写为字符串,请尝试“ writeRawValue”。
var express = require('express');
var app = express();
var nodeExcel = require('excel-export');
var conf = {}
conf.cols = [{
caption: 'Sl.',
type: 'number',
width: 3
}];
var arr = [];
arr.push([1]);
conf.rows = arr;
var result = nodeExcel.execute(conf);
app.get('/',function(req,res){
res.setHeader('Content-Type', 'application/vnd.openxmlformats');
res.setHeader("Content-Disposition", "attachment; filename=" +
"Report.xlsx");
res.writeHead(200);
res.end(result, 'binary');
});
app.listen(3000,function(){
console.log("listening port 3000");
});