package com.zcxk.charge.web.util.jsonserializer;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;

import java.io.IOException;
import java.text.DecimalFormat;

/**
 * @description Double保留三位小数
 * @author   wangli
 * @data 2020/12/31 14:17
 */
public class DoubleJsonSerializer extends JsonSerializer<Double> {

    private DecimalFormat df = new DecimalFormat("0.000");
    @Override
    public void serialize(Double aDouble, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {
        if(aDouble != null) {
            jsonGenerator.writeString(df.format(aDouble));
        }
    }
}
