tommy

It's hard to tell the world we live in is either a reality or a dream
posts - 52, comments - 17, trackbacks - 0, articles - 0
  C++博客 :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理

javascript float problem

Posted on 2011-11-22 18:16 Tommy Liang 阅读(314) 评论(0)  编辑 收藏 引用
<script language=javascript>
function ceil(number,significance){
if(significance){
return Math.ceil(number/significance) * significance;
}
return Math.ceil(number);
}
document.write(ceil((2025.4/(2000+2*19.05-12.7)).toFixed(3),1));
document.write("<br/>");
document.write(ceil(2.98,2));
</script>

note:  ceil((2025.4/(2000+2*19.05-12.7)),1) = 2, because of float problem, toFixed(prec) fix the problem.

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理