javascript取整 取余等操作

论坛 期权论坛 编程之家     
选择匿名的用户   2021-6-2 17:04   742   0
<script type="text/javascript">
<!--
var app = app || {};
app.ctx = '/';
app.zTreeLoadTreeId="J_tree_module";
app.popWidth=550;
app.popHeight=app.popWidth*0.618;
document.writeln("<br>app.popWidth:"+app.popWidth+"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;app.popHeight:"+app.popHeight);
document.writeln("<br>丢弃小数部分,保留整数部分:parseInt(app.popHeight)="+parseInt(app.popHeight));
document.writeln("<br>向上取整,有小数,则整数部分加1:Math.ceil(app.popHeight)="+Math.ceil(app.popHeight));


document.writeln("<br>四舍五入:Math.round(app.popHeight)="+Math.round(app.popHeight));
document.writeln("<br>向下取整:Math.floor(app.popHeight)="+Math.floor(app.popHeight));
document.writeln("<br>取余数 % : app.popHeight % app.popWidth="+ app.popHeight % app.popWidth);
document.writeln("<br>取余数 % : 0% 3="+ (0%3));
document.writeln("<br>取余数 % : 1% 3="+ (1%3));
document.writeln("<br>取余数 % : 2% 3="+ (2%3));
document.writeln("<br>取余数 % : 3% 3="+ (3%3));
document.writeln("<br>取余数 % : 4% 3="+ (4%3));
document.writeln("<br>取余数 % : 5% 3="+ (5%3));
document.writeln("<br>取余数 % : 6% 3="+ (6%3));
document.writeln("<br>取余数 % : 7% 3="+ (7%3));


//app.popWidth:550 app.popHeight:339.9
//丢弃小数部分,保留整数部分:parseInt(app.popHeight)=339
//向上取整,有小数,则整数部分加1:Math.ceil(app.popHeight)=340
//四舍五入:Math.round(app.popHeight)=340
//向下取整:Math.floor(app.popHeight)=339
//取余数 % : app.popHeight % app.popWidth=339.9
//取余数 % : 0% 3=0
//取余数 % : 1% 3=1
//取余数 % : 2% 3=2
//取余数 % : 3% 3=0
//取余数 % : 4% 3=1
//取余数 % : 5% 3=2
//取余数 % : 6% 3=0
//取余数 % : 7% 3=1
//-->
</script>
分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:3875789
帖子:775174
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP