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

org.sql2o.converters.BigDecimalConverter Maven / Gradle / Ivy

There is a newer version: 0.2.6
Show newest version
package org.sql2o.converters;

import java.math.BigDecimal;

/**
 * Used by sql2o to convert a value from the database into a {@link BigDecimal}.
 */
public class BigDecimalConverter extends NumberConverter{

    public BigDecimalConverter() {
        super(false);
    }

    @Override
    protected BigDecimal convertNumberValue(Number val) {
        if (val instanceof BigDecimal){
            return (BigDecimal)val;
        }
        else{
            return BigDecimal.valueOf(val.doubleValue());
        }
    }

    @Override
    protected BigDecimal convertStringValue(String val) {
        return BigDecimal.valueOf(Double.parseDouble(val));
    }

    @Override
    protected String getTypeDescription() {
        return BigDecimal.class.toString();
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy