Search in sources :

Example 1 with NumberPointType

use of org.thymeleaf.util.NumberPointType in project thymeleaf by thymeleaf.

the class Numbers method formatDecimal.

public String formatDecimal(final Number target, final Integer minIntegerDigits, final String thousandsPointType, final Integer decimalDigits, final String decimalPointType) {
    if (target == null) {
        return null;
    }
    final NumberPointType decimalNumberPointType = NumberPointType.match(decimalPointType);
    if (decimalNumberPointType == null) {
        throw new TemplateProcessingException("Unrecognized point format \"" + decimalPointType + "\"");
    }
    final NumberPointType thousandsNumberPointType = NumberPointType.match(thousandsPointType);
    if (thousandsNumberPointType == null) {
        throw new TemplateProcessingException("Unrecognized point format \"" + thousandsPointType + "\"");
    }
    try {
        return NumberUtils.format(target, minIntegerDigits, thousandsNumberPointType, decimalDigits, decimalNumberPointType, this.locale);
    } catch (final Exception e) {
        throw new TemplateProcessingException("Error formatting decimal with minimum integer digits = " + minIntegerDigits + ", thousands point type = " + thousandsPointType + ", decimal digits = " + decimalDigits + " and decimal point type = " + decimalPointType, e);
    }
}
Also used : NumberPointType(org.thymeleaf.util.NumberPointType) TemplateProcessingException(org.thymeleaf.exceptions.TemplateProcessingException) TemplateProcessingException(org.thymeleaf.exceptions.TemplateProcessingException)

Aggregations

TemplateProcessingException (org.thymeleaf.exceptions.TemplateProcessingException)1 NumberPointType (org.thymeleaf.util.NumberPointType)1