⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 decimalbox.java

📁 ZK 基础介绍 功能操作 模块 结合数据库操作
💻 JAVA
字号:
/* Decimalbox.java{{IS_NOTE	Purpose:			Description:			History:		Tue Jun 28 13:40:20     2005, Created by tomyeh}}IS_NOTECopyright (C) 2005 Potix Corporation. All Rights Reserved.{{IS_RIGHT	This program is distributed under GPL Version 2.0 in the hope that	it will be useful, but WITHOUT ANY WARRANTY.}}IS_RIGHT*/package org.zkoss.zul;import java.math.BigDecimal;import org.zkoss.math.BigDecimals;import org.zkoss.zk.ui.WrongValueException;import org.zkoss.zul.mesg.MZul;import org.zkoss.zul.impl.NumberInputElement;/** * An edit box for holding BigDecimal. * * @author tomyeh */public class Decimalbox extends NumberInputElement {	/** Used with {@link #setScale} to denote that the scale is decided by	 * what user has entered.	 */	public static final int AUTO = -1000000000;	private int _scale = AUTO;	public Decimalbox() {		setCols(11);	}	public Decimalbox(BigDecimal value) throws WrongValueException {		this();		setValue(value);	}	/** Returns the value (in BigDecimal), might be null unless	 * a constraint stops it.	 * @exception WrongValueException if user entered a wrong value	 */	public BigDecimal getValue() throws WrongValueException {		return (BigDecimal)getTargetValue();	}	/** Returns the value in double. If null, zero is returned.	 */	public double doubleValue() throws WrongValueException {		final BigDecimal val = getValue();		return val != null ? val.doubleValue(): 0.0;	}	/** Returns the value in integer. If null, zero is returned.	 */	public int intValue() throws WrongValueException {		final BigDecimal val = getValue();		return val != null ? val.intValue(): 0;	}	/** Returns the value in long. If null, zero is returned.	 */	public long longValue() throws WrongValueException {		final BigDecimal val = getValue();		return val != null ? val.longValue(): 0;	}	/** Returns the value in short. If null, zero is returned.	 */	public short shortValue() throws WrongValueException {		final BigDecimal val = getValue();		return val != null ? val.shortValue(): 0;	}	/** Sets the value (in BigDecimal).	 * @exception WrongValueException if value is wrong	 */	public void setValue(BigDecimal value) throws WrongValueException {		validate(value);		setRawValue(value);	}	/** Returns the scale for the decimal number storing in this component,	 * or {@link #AUTO} if the scale is decided automatically (based on	 * what user has entered).	 *	 * <p>Default: {@link #AUTO}.	 */	public int getScale() {		return _scale;	}	/** Returns the scale for the decimal number storing in this component,	 * or {@link #AUTO} if the scale is decided automatically (based on	 * what user has entered).	 *	 * <p>Default: {@link #AUTO}.	 */	public void setScale(int scale) {		_scale = scale;	}	//-- super --//	protected Object coerceFromString(String value) throws WrongValueException {		final Object[] vals = toNumberOnly(value);		final String val = (String)vals[0];		if (val == null || val.length() == 0)			return null;		try {			BigDecimal v = new BigDecimal(val);			if (_scale != AUTO)				v = v.setScale(_scale, getRoundingMode());			int divscale = vals[1] != null ? ((Integer)vals[1]).intValue(): 0;			if (divscale > 0) {				final BigDecimal ten = new BigDecimal(10);				do {					v = v.divide(ten, _scale == AUTO ? v.scale()+1: _scale,						getRoundingMode());				} while (--divscale > 0);			}			return v;		} catch (NumberFormatException ex) {			throw showCustomError(				new WrongValueException(this, MZul.NUMBER_REQUIRED, value));		}	}	protected String coerceToString(Object value) {		return formatNumber(value, "0.##########");	}}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -