Javascript -- Math.round()、Math.ceil()、Math.floor()、parseInt去小数取整总结
一、Math.round()
作用:四舍五入返回整数。(返回参数+0.5后,向下取整)
Math.round(5.57) //返回6
Math.round(2.4) //返回2
Math.round(-1.5) //返回-1
Math.round(-5.8) //返回-6
二、Math.ceil()
作用:返回大于等于参数的最小整数。
Math.ceil(5.57) //返回6
Math.ceil(2.4) //返回3
Math.ceil(-1.5) //返回-1
Math.ceil(-5.8) //返回-5
三、Math.floor()
作用:返回小于等于参数的最大整数。
Math.floor(5.57) //返回5
Math.floor(2.4) //返回2
Math.floor(-1.5) //返回-2
Math.floor(-5.8) //返回-6
四、parseInt()
作用:解析一个字符串,并返回一个整数,这里可以简单理解成返回舍去参数的小数部分后的整数。
parseInt(5.57) //返回5
parseInt(2.4) //返回2
parseInt(-1.5) //返回-1
parseInt(-5.8) //返回-5
正数转换和Math.floor()一样,负数不一样
Javascript -- Math.round()、Math.ceil()、Math.floor()、parseInt去小数取整总结的更多相关文章
- js中Math.round、parseInt、Math.floor和Math.ceil小数取整总结(转)
js中Math.round.parseInt.Math.floor和Math.ceil小数取整总结 Math.round.parseInt.Math.floor和Math.ceil 都可以返回一个整数 ...
- Math类中round、ceil和floor方法的功能
Java中的Math工具类用来完成除+.-.*./.%等基本运算以外的复杂运算,位于java.lang包下,Math类的构造器全是私有的(private),因此无法创建Math类的对象,Math类的方 ...
- 【转载】Javascript使用Math.floor方法向下取整
在Javascript的数值运算中,很多时候需要对最后计算结果向下取整,Math.floor是javascript中对计算结果向下取整的函数,它总是将数值向下舍入为最接近的整数.此外Math.ceil ...
- php中除法取整的方法(round,ceil,floor)
PHP中遇到需要将除法所得结果取整的情况时,就需要用到以下方法: 1. round:四舍五入 round() 函数对浮点数进行四舍五入. 语法:round(x, prec) 参数 描述 x 可选.规定 ...
- javaScript中小数取整,四种方法的比较
1.parseInt:只取整数位例如:parseInt(3.7) 取整结果为:3parseInt(-1.1) 取整结果为:-1 2.Math.floor :向下去整,取大的整数例如:Math.floo ...
- js中Math.round、parseInt、Math.floor和Math.ceil小数取整总结
Math.round.parseInt.Math.floor和Math.ceil 都可以返回一个整数,具体的区别请看下面的总结. 一.Math.round 作用:四舍五入,返回参数+0.5后,向下取整 ...
- js中Math.round、parseInt、Math.floor和Math.ceil小数取整小结
以前经常在代码中看到Math.round.parseInt.Math.floor和Math.ceil这四个函数,虽然知道结果都可以返回一个整数,但是对他们四者的区别还是不太清楚,今天就做一个小结. 一 ...
- js中Math.round、parseInt、Math.floor和Math.ceil小数取整小结【转】
[摘要:之前常常正在代码中看到Math.round.parseInt.Math.floor战Math.ceil那四个函数,固然晓得效果皆能够返回一个整数,然则对他们四者的差别照样没有太清晰,本日便做一 ...
- JavaScript里Math对象的ceil()、floor()、round()方法的区别
ceil(x) 官方含义:对一个数进行上舍入.理解:ceiling为天花板的意思,意译为向上取整.即取得大于于等于x的最大整数. floor(x) 官方含义:对一个数进行下舍入.理解:floor为地板 ...
随机推荐
- HttpContext及HttpContext.current
慎用System.Web.HttpContext.Current http://www.cnblogs.com/david1989/p/3879201.html 线程编程中用到HttpContext. ...
- PING的原理以及ICMP协议
主要内容: 1.ping的原理以及工作过程 2.ICMP协议 3.ICMP的应用:ping,traceroute 1.ping的原理以及工作过程 ping的原理 ping 程序是用来探测主机到主机 ...
- Android Studio Push rejected: Push to origin/Alpha1.0 was rejected
android studio git 右键项目, git pull 刷新选择Alpha1.0同步后,再commit and push
- icacls备份与还原ACL列表(NTFS权限)--Robocopy
icacls c:\windows\* /save AclFile /T- 将 c:\windows 及其子目录下所有文件的 ACL 保存到 AclFile. icacls c:\windows\ / ...
- 查看sid
查看用户sid: whoami /user 查看系统sid: 使用PSTools工具中的 psgetsid.exe命令查看
- Codeforces Round #180 (Div. 2) D. Fish Weight 贪心
D. Fish Weight 题目连接: http://www.codeforces.com/contest/298/problem/D Description It is known that th ...
- 一步步学习PHP笔记(李炎恢瓢城web俱乐部-多用户留言系统)01
本课:div+css实现首页效果: 开发工具:xampp + phpstorm 笔记目的:仅做记录使用,方便日后查看 代码目录结构: index.php: <?php define(" ...
- iOS CocoaPods安装和使用图解
Cocoapods安装步骤 1.升级Ruby环境 sudo gem update --system 如果Ruby没有安装,请参考 如何在Mac OS X上安装 Ruby运行环境 2.安装CocoaPo ...
- /proc/sys/vm/ 内存参数
linux下proc里关于磁盘性能的参数 http://blog.csdn.net/eroswang/article/details/6126646 我们在磁盘写操作持续繁忙的服务器上曾经碰到一个特 ...
- linux man使用方法 和centos安装中文man包 --转
http://blog.chinaunix.net/uid-25100840-id-302308.html 这两天学习<linux设备驱动程序开发详解>中的异步通知,其中有一个fcntl( ...