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

📄 decimalbox.java

📁 非常接近C/S操作方式的Java Ajax框架-ZK 用ZK框架使你的B/S应用程序更漂亮更易操作。 官网:www.zkoss.org
💻 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.FormatInputElement;/** * An edit box for holding BigDecimal. * * @author tomyeh */public class Decimalbox extends FormatInputElement {	/** 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)getRawValue();	}	/** 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 String val = toNumberOnly(value);		if (val == null || val.length() == 0)			return null;		try {			int j = val.indexOf('%'); //toNumberOnly translates Locale-dependent			BigDecimal bd = j == 0 ? new BigDecimal(0D):				new BigDecimal(j < 0 ? val: val.substring(0, j));			if (_scale != AUTO) bd = bd.setScale(_scale);			if (j < 0) return bd;			final BigDecimal hundred = new BigDecimal(100);			for (final int len = val.length(); j < len && bd.signum() != 0; ++j)				if (val.charAt(j) == '%')					bd = bd.divide(hundred,						_scale == AUTO ? bd.scale()+2: _scale,						BigDecimal.ROUND_HALF_EVEN);				else					throw new WrongValueException(this, MZul.NUMBER_REQUIRED, value);			return bd;		} catch (NumberFormatException ex) {			throw 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 + -