All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.jslsolucoes.spring.converter.BigDecimalConverter Maven / Gradle / Ivy

There is a newer version: 1.0.34
Show newest version
package com.jslsolucoes.spring.converter;

import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.text.ParseException;

import org.apache.commons.lang3.StringUtils;
import org.springframework.core.convert.converter.Converter;

public class BigDecimalConverter implements Converter {

    @Override
    public BigDecimal convert(String value) {
	if (StringUtils.isEmpty(value)) {
	    return null;
	}
	try {
	    return new BigDecimal(value);
	} catch (NumberFormatException e) {
	    try {
		DecimalFormat fmt = new DecimalFormat("#,##0.00");
		fmt.setParseBigDecimal(true);
		return (BigDecimal) fmt.parse(value);
	    } catch (ParseException pe) {
		throw new RuntimeException(pe);
	    }
	}
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy