JS动态显示今天已过去了百分之多少,不过有一长串很多小数位,如何将输出的小数位截取到小数点后4位? 80

<!DOCTYPEHTMLPUBLIC"-//W3C//DTDHTML4.01Transitional//EN""http://www.w3.org/TR/html4/l... <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
</head>
<body>
<form name="form1">
<div align="center" align="middle">
<center>今天已度过了:<br>
<div ><input type="textarea" name="left" style="text-align: center;font-size:30px;border:none;overflow:hidden"> </div>
</center>
</div>
</form>
<script LANGUAGE="javascript">
startclock()
var timerID = null;
var timerRunning = false;
function showtime() {
Today = new Date();
var NowHour = Today.getHours();
var NowMinute = Today.getMinutes();
var NowMonth = Today.getMonth();
var NowDate = Today.getDate();
var NowYear = Today.getYear();
var NowSecond = Today.getSeconds();
if (NowYear <2000)
NowYear=1900+NowYear;
Today = null;
Hourleft = 23 - NowHour
Minuteleft = 59 - NowMinute
Secondleft = 59 - NowSecond
Yearleft = 2048 - NowYear
Monthleft = 22 - NowMonth - 1
Dateleft = 31 - NowDate
if (Secondleft<0)
{
Secondleft=60+Secondleft;
Minuteleft=Minuteleft-1;
}
if (Minuteleft<0)
{
Minuteleft=60+Minuteleft;
Hourleft=Hourleft-1;
}
if (Hourleft<0)
{
Hourleft=24+Hourleft;
Dateleft=Dateleft-1;
}
if (Dateleft<0)
{
Dateleft=31+Dateleft;
Monthleft=Monthleft-1;
}
if (Monthleft<0)
{
Monthleft=12+Monthleft;
Yearleft=Yearleft-1;
}
else if (0<Monthleft<12)
{
Monthleft=Monthleft;
Yearleft=Yearleft;
}
else (Monthleft>12)
{
Monthleft=Monthleft-12;
Yearleft=Yearleft+1;
}
Temp=(((1-(3600*Hourleft+60*Minuteleft+Secondleft)/86400)*100)+'%')
document.form1.left.value=Temp;
timerID = setTimeout("showtime()",1000);
timerRunning = true;
}
var timerID = null;
var timerRunning = false;
function stopclock () {
if(timerRunning)
clearTimeout(timerID);
timerRunning = false;
}
function startclock () {
stopclock();
showtime();
}
// -->
</script>
</body>
</html>
展开
 我来答
百度网友c09f772
2012-09-06
知道答主
回答量:6
采纳率:0%
帮助的人:5.3万
展开全部

//Temp=(((1-(3600*Hourleft+60*Minuteleft+Secondleft)/86400)*100)+'%')
改成下面就可以了
TempT = ((1-(3600*Hourleft+60*Minuteleft+Secondleft)/86400)*100)
Temp = (TempT.toFixed(4) + '%');

toFixed()方法 按照指定的小数位返回数值
本回答被网友采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式