【转载】Javascript使用Math.floor方法向下取整
在Javascript的数值运算中,很多时候需要对最后计算结果向下取整,Math.floor是javascript中对计算结果向下取整的函数,它总是将数值向下舍入为最接近的整数。此外Math.ceil()函数则是javascript中向上取整函数,Math.round()方法可对计算结果进行四舍五入操作。
例如一个数值变量 var num=25.4。对num变量向下取整可使用
var floorNum=Math.floor(num);//计算结果为floorNum=25。
如果需要对num变量进行向上取整,则使用Math.ceil()函数来实现
var ceilNum=Math.ceil(num);//计算结果为ceilNum=26。
对num变量进行四舍五入取整,则使用Math.round()函数来实现
var roundNum=Math.roundNum(num);//计算结果为roundNum=25。
备注:原文转载自博主个人技术站IT技术小趣屋,原文链接Javascript使用Math.floor方法向下取整_IT技术小趣屋。
博主个人技术交流群:960640092,博主微信公众号如下:

【转载】Javascript使用Math.floor方法向下取整的更多相关文章
- floor()函数 向下取整 ceil()函数向上取整
floor(x) is the largest integer not greater than x , 也就是,floor(x) 返回的是小于等于x的所有整数中最大的整数,简单的说,就是去掉x的小 ...
- c# 三种取整方法 向上取整 向下取整 四舍五入
Math.Round:四舍六入五取整 Math.Ceiling:向上取整,只要有小数都加1 Math.Floor:向下取整,总是舍去小数
- Python向上取整,向下取整以及四舍五入函数
import math f = 11.2 print math.ceil(f) #向上取整 print math.floor(f) #向下取整 print round(f) #四舍五入 #这三个函数的 ...
- Python 之 向上取整、向下取整以及四舍五入函数
import math f = 11.2 print math.ceil(f) #向上取整 print math.floor(f) #向下取整 print round(f) #四舍五入 #这三个函数的 ...
- Java关于Math类的三个取整方法
0x01 在java的Math类中有三个关于浮点数取整数的方法,分别是ceil (向上取整) floor(向下取整) round(四舍五入) 三个方法 0x02 ceil 向上取整,取整后总是比原来的 ...
- python向上取整 向下取整
向上取整 ceil() 函数返回数字的向上取整整数,就是返回大于等于变量的最近的整数. ceil()是不能直接访问的,需要导入 math 模块. import math math.ceil( x ) ...
- python 向下取整,向上取整,四舍五入
# python 向下取整 floor 向上取整ceil 四舍五入 round import math num=3.1415926 # 向上取整 print(math.ceil(num)) # 向下取 ...
- sql 中取整,四舍五入取整,向下取整,向上取整。
SELECT round(52.45, 0) AS round4, round(52.54, 0) AS round5, round(52.45, 1) AS round41, round(52.54 ...
- c++ 向上取整和向下取整
在c++ 中: ceil()表示向上取整 floor()表示向下取整 当然,这很显然对浮点数很好用. 但如果两个int类型的数想要向上取整呢? 我们用 (n-1)/m+1 来表示即可.
随机推荐
- mysql 面试题 查询出表中某字段的重复值
users 表中有 两个字段 id 和 name 表数据大概如下: id name 1 AAA 2 BBB 3 CCC 4 AAA 请写查 ...
- 平时常说的ThreadLocal,今天就彻底解决它
前言 一.了解ThreadLocal的作用 二.ThreadLocal简单使用 三.ThreadLocal原理 3.1 ThreadLocal的存取过程 3.2 探究ThreadLocalMap对象 ...
- js 模糊搜索
function fuzzysearch (needle, haystack) { var hlen = haystack.length; var nlen = needle.length; if ( ...
- python中urllib的urlencode与urldecode
当url地址含有中文,或者参数有中文的时候,这个算是很正常了,但是把这样的url作为参数传递的时候(最常见的callback),需要把一些中文甚至'/'做一下编码转换. urlencode urlli ...
- [LeetCode] 20. Valid Parentheses 合法括号
Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the inpu ...
- [LeetCode] 340. Longest Substring with At Most K Distinct Characters 最多有K个不同字符的最长子串
Given a string, find the length of the longest substring T that contains at most k distinct characte ...
- 记录一次使用iisnode部署node项目遇到的坑!
前言:最近因为项目原因,需要在IIS下部署node项目,在此之前,曾经部署过类似的项目,因此在这次部署还算比较顺利,只是在其中遇到了几个比较坑的问题,所以这次使用博客记录下来,如有园友遇到过类似问题, ...
- Mac打开原生NTFS功能
一.在 terminal 里输入 diskutil list 查看 U 盘的 NAME diskutil list 二.执行以下命令,输入密码 sudo nano /etc/fstab 三.把U盘信息 ...
- [转帖]Redis、Memcache和MongoDB的区别
Redis.Memcache和MongoDB的区别 https://www.cnblogs.com/tuyile006/p/6382062.html >>Memcached Memcach ...
- 目标检测算法Faster R-CNN
一:Faster-R-CNN算法组成: 1.PRN候选框提取模块: 2.Fast R-CNN检测模块. 二:Faster-R-CNN框架介绍 三:RPN介绍 3.1训练步骤:1.将图片输入到VGG或Z ...