ThousandConvert.java 1.03 KB
Newer Older
Memorydoc's avatar
#  
Memorydoc committed
1 2 3 4 5 6 7 8 9 10
package pwc.taxtech.atms.common;


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

import java.io.IOException;
import java.math.BigDecimal;
Memorydoc's avatar
#  
Memorydoc committed
11
import java.math.RoundingMode;
Memorydoc's avatar
#  
Memorydoc committed
12 13 14 15 16 17 18 19 20 21 22 23 24 25
import java.text.NumberFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

/**
 * author kevin
 * target : Solve ThousandConvert
 * version 1.0
 */
public class ThousandConvert extends JsonSerializer<BigDecimal> {
    @Override
    public void serialize(BigDecimal value, JsonGenerator jgen, SerializerProvider arg2)
            throws IOException {
Memorydoc's avatar
#  
Memorydoc committed
26 27 28 29 30
        NumberFormat integerInstance = NumberFormat.getIntegerInstance(Locale.getDefault());
        integerInstance.setMinimumFractionDigits(2);
        integerInstance.setRoundingMode(RoundingMode.HALF_UP);
        integerInstance.setGroupingUsed(true);
        jgen.writeString(integerInstance.format(value));
Memorydoc's avatar
#  
Memorydoc committed
31 32
    }
}