org.ztemplates.property.ZBigDecimalProperty Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ztemplates Show documentation
Show all versions of ztemplates Show documentation
java web framework - annotations - pojo - NO XML -
state-free - clean, technology agnostic urls - REST -
invisible to the web-client -
JSP, Velocity, FreeMarker (others pluggable) -
annotations for JavaScript/CSS dependencies - create reusable components
The newest version!
/*
* 11.12.2005
* @author www.gerdziegler.de
*/
package org.ztemplates.property;
import java.math.BigDecimal;
public class ZBigDecimalProperty extends ZProperty
{
private int scale = -1;
private int roundingMode = BigDecimal.ROUND_HALF_UP;
public ZBigDecimalProperty()
{
}
public ZBigDecimalProperty(int scale, int roundingMode)
{
this.scale = scale;
this.roundingMode = roundingMode;
}
public ZBigDecimalProperty(BigDecimal val)
{
setValue(val);
}
public BigDecimal parse(String formattedValue) throws Exception
{
BigDecimal i = new BigDecimal(formattedValue);
if (scale >= 0)
{
i.setScale(scale, roundingMode);
}
return i;
}
public String format(BigDecimal obj)
{
return obj == null ? null : obj.toString();
}
public int getScale()
{
return scale;
}
}