JS-Math对象


<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Math对象练习</title>
</head>
<body>
<h1>Math属性代码验证</h1>
<input type="button" value="点击" onclick="a()"/><br/>
<span id="x"></span>
<script type="text/javascript">
var x = document.getElementById('x');
function a(){
x.innerHTML = Math.E + '——返回算数常量e,即自然对数的底数。<br/>' +Math.LN2 +'——返回2的自然对数<br/>'+Math.LN10+'——返回10的自然对数<br/>'+Math.LOG2E+'——返回以2为底的e的对数<br/>'+Math.LOG10E+'——返回以10为底的e的对数<br/>'+Math.PI+'——返回圆周率<br/>'+Math.SQRT1_2+'——返回2的平方根的倒数<br/>'+ Math.SQRT2 + '——返回2的平方根';
}//这里很奇怪的是,如果id为x的容器表现是textarea的话,换行符需要用\n才管用,换成了p、span、a等标签,用<br />就可以了
</script>
<h1>Math方法代码验证</h1>
<h3>ceil(x)向上舍入</h3>
<script type="text/javascript">
document.write('0.3向上取舍变成》》'+Math.ceil(0.3)+'<br />');
document.write('0.9》》'+Math.ceil(0.9)+'<br />');
document.write('6.3》》'+Math.ceil(6.3)+'<br />');
document.write('5》》'+Math.ceil(5)+'<br />');
document.write('3.5》》'+Math.ceil(3.5)+'<br />');
document.write('-5.1》》'+Math.ceil(-5.1)+'<br />');
document.write('-5.9》》'+Math.ceil(-5.9)+'<br />');
</script>
<h3>floor(x)向下舍入</h3>
<script type="text/javascript">
document.write('0.3向下取舍变成》》'+Math.floor(0.3)+'<br />');
document.write('0.9》》'+Math.floor(0.9)+'<br />');
document.write('6.3》》'+Math.floor(6.3)+'<br />');
document.write('5》》'+Math.floor(5)+'<br />');
document.write('3.5》》'+Math.floor(3.5)+'<br />');
document.write('-5.1》》'+Math.floor(-5.1)+'<br />');
document.write('-5.9》》'+Math.floor(-5.9)+'<br />');
</script>
<h3>round(x)四舍五入</h3>
<script type="text/javascript">
document.write('0.3四舍五入变成》》'+Math.round(0.3)+'<br />');
document.write('0.9》》'+Math.round(0.9)+'<br />');
document.write('6.3》》'+Math.round(6.3)+'<br />');
document.write('5》》'+Math.round(5)+'<br />');
document.write('3.5》》'+Math.round(3.5)+'对于0.5,进行上舍入<br />');
document.write('-5.1》》'+Math.round(-5.1)+'<br />');
document.write('-5.9》》'+Math.round(-5.9)+'<br />');
document.write('-5.5》》'+Math.round(-5.5)+'若两边相同接近,则结果接近x轴正方向的正无穷方向<br />');
document.write('-5.52》》'+Math.round(-5.52)+'<br />');
</script>
</body>
</html>
JS-Math对象的更多相关文章
- JS Math对象中一些小技巧
JS中快速获取数组中最大/最小值 var a=[1,2,3,5]; alert(Math.max.apply(Math, a));//最大值 alert(Math.min.apply(Math, a) ...
- js Math 对象的方法
Math对象与JavaScript其他对象不同,因为用户不能生成所使用对象的副本,相反脚本汇集了简单Math对象的属性和方法.Math对象实际上存在于每个窗口和框架中,但是对脚本没有影响,程序员把这种 ...
- js math对象总结
1: Math 对象用于执行数学任务. 2:Math 对象并不像 Date 和 String 那样是对象的类,因此没有构造函数 Math(), Math.sin() 这样的函数只是函数 3:通过把 ...
- JS:Math 对象方法
Math 对象方法方法 描述Math.ceil(x) 对数进行上舍入.(向上取整:大于等于x的最小整数)Math.floor(x) 对数进行下舍入.(小于等于x的最大整数)Ma ...
- js Math 对象
Math 对象方法 方法 描述 abs(x) 返回数的绝对值. acos(x) 返回数的反余弦值. asin(x) 返回数的反正弦值. atan(x) 以介于 -PI/2 与 PI/2 弧度之间的数值 ...
- JS Math对象、日期对象、函数、定时器
Math对象 开平方:sqrt 绝对值:abs π:PI x的y次方:pow 四舍五入取整:round 向下取整:floor 向上取整:ceil 最大值:max 最小值: min 随机数:random ...
- js Math对象的常用方法
1,基本方法: Math.round();向上四舍五入. Math.ceil();向上取整,有小数就整数部分加1 Math.floor(5/2) ;向下取整 Math.abs();返回绝对值: Mat ...
- 原生JS:Math对象详解
Math对象 本文参考MDN做的详细整理,方便大家参考MDN Math 也是一个内置对象, 为数学常量和数学函数提供了属性和方法,而不是一个函数对象. 与其它全局对象不同的是, Math 不是一个构造 ...
- JavaScript基础14——js的Math对象
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- js中的函数,Date对象,Math对象和数组对象
函数就是完成某个功能的一组语句,js中的函数由关键字 function + 函数名 + 一组参数定义;函数在定义后可以被重复调用,通常将常用的功能写成一个函数,利用函数可以使代码的组织结构更多清晰. ...
随机推荐
- How to remove a batch of VMs and related Disks
Foreword Need to remove a batch of VMs, which named with same prefix or belong to same Cloud Service ...
- springmvc整合fastjson
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.sp ...
- Ubuntu disk error
I have heard that ext file system is easy to crash. Today i forced to shutdown Ubuntu. As a result,i ...
- [cross domain] four approachs to cross domain in javascript
four approachs can cross domain in javascript 1.jsonp 2.document.domain(only in frame and they have ...
- git flow的使用
简介 Gitflow工作流程围绕项目发布定义了严格的分支模型.尽管它比Feature Branch Workflow更复杂一些,但它也为管理更大规模的项目提供了坚实的框架. 与Feature Bran ...
- Android M 控件:AppBarLayout,CoordinatorLayout,CollapsingToolbarLayout
AppBarLayout AppBarLayout跟它的名字一样,把容器类的组件全部作为AppBar.是继承LinerLayout实现的一个ViewGroup容器组件,它是为了Material Des ...
- 标题栏ToolBar
使用标题栏ToolBar 首先需要在AndroidManifest.xml中修改 application主题或者activity主题 隐藏原生标题栏 在styles.xml中自定义主题 a ...
- 时间复杂度---我又要想起初中数学老师的脸了xxxxx
时间复杂度: 常用的时间复杂度有:常数级,对数级,线性级 线性对数级 平方级,立方级别,多项式级别,指数级别,阶乘级别 这里我们主要探讨对数级,线性级,平方级,指数级---为什么不讨论其他的?别的我也 ...
- matlab之meshgrid()函数
以最常见的一个用法为例: [X,Y]=meshgrid(xgv, ygv) xgv是一个(一维的,行)向量,ygv也是. 产生的X和Y,规格相同,都是二维向量,高度为size(ygv,2),宽度为si ...
- Diccuz!NT的dll版本号控制技巧
dnt每次发布新版本时,公布出来的版本号都是3位数以上,拿3.6.711这个版本号的代码来说,几乎每一个dll上都是统一的版本号命名: 对于一个成熟的产品来说,统一一致的版本号命名有以下的好处: 1. ...