com.alibaba.excel.util.NumberDataFormatterUtils Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of easyexcel Show documentation
Show all versions of easyexcel Show documentation
easyexcel is a excel handle tools written in Java
package com.alibaba.excel.util;
import com.alibaba.excel.metadata.format.DataFormatter;
import com.alibaba.excel.metadata.GlobalConfiguration;
/**
* Convert number data, including date.
*
* @author Jiaju Zhuang
**/
public class NumberDataFormatterUtils {
/**
* Cache DataFormatter.
*/
private static final ThreadLocal DATA_FORMATTER_THREAD_LOCAL = new ThreadLocal();
/**
* Format number data.
*
* @param data
* @param dataFormat Not null.
* @param dataFormatString
* @param globalConfiguration
* @return
*/
public static String format(Double data, Integer dataFormat, String dataFormatString,
GlobalConfiguration globalConfiguration) {
DataFormatter dataFormatter = DATA_FORMATTER_THREAD_LOCAL.get();
if (dataFormatter == null) {
dataFormatter = new DataFormatter(globalConfiguration);
DATA_FORMATTER_THREAD_LOCAL.set(dataFormatter);
}
return dataFormatter.format(data, dataFormat, dataFormatString);
}
public static void removeThreadLocalCache() {
DATA_FORMATTER_THREAD_LOCAL.remove();
}
}