forked from fanruan/easyexcel
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
43 lines
1.2 KiB
43 lines
1.2 KiB
package com.alibaba.excel.util; |
|
|
|
import java.math.BigDecimal; |
|
|
|
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<DataFormatter> DATA_FORMATTER_THREAD_LOCAL = new ThreadLocal<DataFormatter>(); |
|
|
|
/** |
|
* Format number data. |
|
* |
|
* @param data |
|
* @param dataFormat Not null. |
|
* @param dataFormatString |
|
* @param globalConfiguration |
|
* @return |
|
*/ |
|
public static String format(BigDecimal 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(); |
|
} |
|
}
|
|
|