/**
*
* @param value 要四舍五入的值
* @param scale 小数点后要取的位数
* @return
*/
public static double round(double value,int scale){
BigDecimal bd=new BigDecimal(value);
BigDecimal divisor=new BigDecimal(1);
BigDecimal returnValue=bd.divide(divisor, scale,BigDecimal.ROUND_HALF_UP );
return returnValue.doubleValue();
}
txt.addFocusListener(new FocusAdapter() {
public void focusLost(FocusEvent e) {
if (e.isTemporary()) {
return;
}
checkFullSize(txt, "人名", 20);
}
});
public boolean checkFullSize(JTextComponent comp, String desc, int digit) {
if (checkHarf(comp.getText())) {
comp.requestFocus();
JOptionPane.showMessageDialog(null, "full size");
comp.requestFocus();
return false;
}
if (comp.getText().length() > digit) {
JOptionPane.showMessageDialog(null, "exceed digit");
comp.requestFocus();
return false;
}
return true;
}
/**
* 是否为半角
* @param 字符串
* @return 半角true 全角false
*/
private boolean checkHarf(String item) {
byte[] bytes = item.getBytes();
int beams = item.length();
if (beams == bytes.length) {
return true;
} else {
return false;
}
}
posted on 2007-04-09 09:22
aaabbb 阅读(621)
评论(0) 编辑 收藏 所属分类:
java