(1)
var x=100
a = x.toString()
(2)
var x=100;
a = x +""; //JS会自动隐性转换
javascript 将string 变成 int
JScript
var s = "32"
var i = new Number(s)
parseInt()
parseInt()
例如:
parseInt("abc") // Returns NaN.
parseInt("12abc") // Returns 12.
parseInt("12") //Return 12.
==================================================
js 计算月份差 ,天数差
<SCRIPT language="javascript">
//计算月份差
function getMonthNumber(date1,date2){
//默认格式为"20030303",根据自己需要改格式和方法
var year1 = date1.substr(0,4);
var year2 = date2.substr(0,4);
var month1 = date1.substr(4,2);
var month2 = date2.substr(4,2);
var len=(year2-year1)*12+(month2-month1);
return len;
}
var len=getMonthNumber('200403','200504');
//alert('2003-03-03'.replace(/-/g, "/"));
//alert('2003-03-03'.replace(/-/g, ""));
if(len<0){
alert("查询起始月份不能比查询终止月份大.");
}else if(len >11){
alert("查询月份时间段不能超过12个月.");
}
</SCRIPT>
<SCRIPT language="javascript">
//计算天数差
function getDayNumber(date1,date2){
//默认格式为"20030303",根据自己需要改格式和方法
var year1 = date1.substr(0,4);
var year2 = date2.substr(0,4);
var month1 = date1.substr(4,2);
var month2 = date2.substr(4,2);
var day1 = date1.substr(6,2);
var day2 = date2.substr(6,2);
temp1 = year1+"/"+month1+"/"+day1;
temp2 = year2+"/"+month2+"/"+day2;
var dateaa= new Date(temp1);
var datebb = new Date(temp2);
var date = datebb.getTime() - dateaa.getTime();
var time = Math.floor(date / (1000 * 60 * 60 * 24));
alert(time);
}
getDayNumber('20030303','20040503');
</SCRIPT>
============================================
<script >
var v1 = 900;v2 = 1000;
//求模
alert(v1%v2);
//整除
function Div(exp1, exp2) {
var n1 = Math.round(exp1); //四舍五入
var n2 = Math.round(exp2); //四舍五入
var rslt = n1 / n2; //除
if (rslt >= 0) {
rslt = Math.floor(rslt); //返回小于等于原rslt的最大整数。
}
else {
rslt = Math.ceil(rslt); //返回大于等于原rslt的最小整数。
}
return rslt;
}
alert(Div(v1, v2));
</script>
Math.ceil(count / pagesize); //向上整除 4/3=2;
Math.floor(count / pagesize); //向下整除 4/3=1;