공부
[thymeleaf] Utility Objects(Strings, Numbers, Objects, Arrays, Lists, Maps, Messages, Dates, Calendars); comma
승가비
2023. 9. 16. 13:45
728x90
https://hajoung56.tistory.com/72
[Thymeleaf] 타임리프 주요 기능 유틸리티 - Utility Objects(Strings, Numbers, Objects, Arrays, Lists, Maps, Messages,
아래 링크와 같이 이전에는 타임리프 정의와 사용방법에 기본적인 기능들을 간단히 설명하였지만, 이번 글에서 주요 유틸리티를 안내합니다. [Thymeleaf] 정의와 사용방법 Thymeleaf의 정의와 사용하
hajoung56.tistory.com
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import java.math.BigDecimal;
import java.text.NumberFormat;
import java.util.Arrays;
import java.util.List;
@Slf4j
public class CommonUtil {
public static final String DOT = ".";
public static String comma(BigDecimal n) {
return comma(String.valueOf(n));
}
public static String comma(double n) {
return comma(String.valueOf(n));
}
public static String comma(String n) {
try {
List<String> h = Arrays.asList(StringUtils.split(n, CommonUtil.DOT));
String decimal = h.size() == 2 ?
"." + h.get(1) :
"";
return comma(Integer.parseInt(h.get(0))) + decimal;
} catch (Exception e) {
log.warn("NaN <{}>", n);
return n;
}
}
public static String comma(int n) {
return NumberFormat.getNumberInstance().format(n);
}
}
Thousands separator thymeleaf: use apostrophe
I'm using thymeleaf to render my views. Is it possible to use ' (apostrophe) as a thousands seperator? Example: What I want is to replace WHITESPACE in the following example with a Value for an
stackoverflow.com
728x90