5 个解决方案
#1
http://community.csdn.net/Expert/topic/3372/3372482.xml?temp=.2460901
前台控制的可以这样
前台控制的可以这样
#2
<script>
function regInput(reg)
{
var srcElem = event.srcElement
var oSel = document.selection.createRange()
var srcRange = srcElem.createTextRange()
oSel.setEndPoint("StartToStart", srcRange)
var num = oSel.text + String.fromCharCode(event.keyCode) + srcRange.text.substr(oSel.text.length)
event.returnValue = reg.test(num)
}
</script>
小写英文:<xmp style="display:inline"> </xmp><input id=test onkeypress="regInput(/^[a-z]*$/)" style="ime-mode:Disabled"><br>
大写英文:<xmp style="display:inline"> </xmp><input id=test onkeypress="regInput(/^[A-Z]*$/)" style="ime-mode:Disabled"><br>
任意数字:<xmp style="display:inline"> </xmp><input id=test onkeypress="regInput(/^[0-9]*$/)" style="ime-mode:Disabled"><br>
限2位小数:<xmp style="display:inline"> </xmp><input id=test onkeypress="regInput(/^\d*\.?\d{0,2}$/)" style="ime-mode:Disabled"> 如: 123.12<br>
日 期:<xmp style="display:inline"> </xmp><input id=test onkeypress="regInput(/^\d{1,4}([-\/](\d{1,2}([-\/](\d{1,2})?)?)?)?$/)" style="ime-mode:Disabled"> 如: 2002-9-29<br>
任意中文:<xmp style="display:inline"> </xmp><input onkeypress="regInput(/^$/)"><br>
部分英文:<xmp style="display:inline"> </xmp><input onkeypress="regInput(/^[a-e]*$/i)" style="ime-mode:Disabled"> 范围: a,b,c,d,e<br>
部分中文:<xmp style="display:inline"> </xmp>
<script language=javascript>
function checkChinese(oldLength, obj)
{
var oTR = window.document.selection.createRange()
oTR.moveStart("character", -1*(obj.value.length-oldLength))
oTR.text = oTR.text.replace(/[^一二三四五六七八九十]/g, "")
}
</script>
<input onkeypress="return false" onkeydown="setTimeout('checkChinese('+this.value.length+','+this.uniqueID+')', 1)"> 范围: 一二三四五六七八九十<br>
#3
太复杂了有没有简单一点的方法
#4
try this
public static double getDouble(double d)
{
String a=String.valueOf(d);
int dian=a.indexOf(".");
String b=a.substring(0,dian)+"."+a.substring(dian,dian+2);
d=Double.parseDouble(b);
return d;
}
public static double getDouble(double d)
{
String a=String.valueOf(d);
int dian=a.indexOf(".");
String b=a.substring(0,dian)+"."+a.substring(dian,dian+2);
d=Double.parseDouble(b);
return d;
}
#5
最简单方法,记得给分哦
import java.text.DecimalFormat;
public class testDecimalFormat
{
public static void main(String[] args)
{
double d = -1234.1;
DecimalFormat format = new DecimalFormat("0.00");
String s = format.format(d);
System.out.println(s);
}
}
import java.text.DecimalFormat;
public class testDecimalFormat
{
public static void main(String[] args)
{
double d = -1234.1;
DecimalFormat format = new DecimalFormat("0.00");
String s = format.format(d);
System.out.println(s);
}
}
#1
http://community.csdn.net/Expert/topic/3372/3372482.xml?temp=.2460901
前台控制的可以这样
前台控制的可以这样
#2
<script>
function regInput(reg)
{
var srcElem = event.srcElement
var oSel = document.selection.createRange()
var srcRange = srcElem.createTextRange()
oSel.setEndPoint("StartToStart", srcRange)
var num = oSel.text + String.fromCharCode(event.keyCode) + srcRange.text.substr(oSel.text.length)
event.returnValue = reg.test(num)
}
</script>
小写英文:<xmp style="display:inline"> </xmp><input id=test onkeypress="regInput(/^[a-z]*$/)" style="ime-mode:Disabled"><br>
大写英文:<xmp style="display:inline"> </xmp><input id=test onkeypress="regInput(/^[A-Z]*$/)" style="ime-mode:Disabled"><br>
任意数字:<xmp style="display:inline"> </xmp><input id=test onkeypress="regInput(/^[0-9]*$/)" style="ime-mode:Disabled"><br>
限2位小数:<xmp style="display:inline"> </xmp><input id=test onkeypress="regInput(/^\d*\.?\d{0,2}$/)" style="ime-mode:Disabled"> 如: 123.12<br>
日 期:<xmp style="display:inline"> </xmp><input id=test onkeypress="regInput(/^\d{1,4}([-\/](\d{1,2}([-\/](\d{1,2})?)?)?)?$/)" style="ime-mode:Disabled"> 如: 2002-9-29<br>
任意中文:<xmp style="display:inline"> </xmp><input onkeypress="regInput(/^$/)"><br>
部分英文:<xmp style="display:inline"> </xmp><input onkeypress="regInput(/^[a-e]*$/i)" style="ime-mode:Disabled"> 范围: a,b,c,d,e<br>
部分中文:<xmp style="display:inline"> </xmp>
<script language=javascript>
function checkChinese(oldLength, obj)
{
var oTR = window.document.selection.createRange()
oTR.moveStart("character", -1*(obj.value.length-oldLength))
oTR.text = oTR.text.replace(/[^一二三四五六七八九十]/g, "")
}
</script>
<input onkeypress="return false" onkeydown="setTimeout('checkChinese('+this.value.length+','+this.uniqueID+')', 1)"> 范围: 一二三四五六七八九十<br>
#3
太复杂了有没有简单一点的方法
#4
try this
public static double getDouble(double d)
{
String a=String.valueOf(d);
int dian=a.indexOf(".");
String b=a.substring(0,dian)+"."+a.substring(dian,dian+2);
d=Double.parseDouble(b);
return d;
}
public static double getDouble(double d)
{
String a=String.valueOf(d);
int dian=a.indexOf(".");
String b=a.substring(0,dian)+"."+a.substring(dian,dian+2);
d=Double.parseDouble(b);
return d;
}
#5
最简单方法,记得给分哦
import java.text.DecimalFormat;
public class testDecimalFormat
{
public static void main(String[] args)
{
double d = -1234.1;
DecimalFormat format = new DecimalFormat("0.00");
String s = format.format(d);
System.out.println(s);
}
}
import java.text.DecimalFormat;
public class testDecimalFormat
{
public static void main(String[] args)
{
double d = -1234.1;
DecimalFormat format = new DecimalFormat("0.00");
String s = format.format(d);
System.out.println(s);
}
}