在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方法向下取整的更多相关文章

  1. floor()函数 向下取整 ceil()函数向上取整

    floor(x)  is the largest integer not greater than x , 也就是,floor(x) 返回的是小于等于x的所有整数中最大的整数,简单的说,就是去掉x的小 ...

  2. c# 三种取整方法 向上取整 向下取整 四舍五入

    Math.Round:四舍六入五取整 Math.Ceiling:向上取整,只要有小数都加1 Math.Floor:向下取整,总是舍去小数

  3. Python向上取整,向下取整以及四舍五入函数

    import math f = 11.2 print math.ceil(f) #向上取整 print math.floor(f) #向下取整 print round(f) #四舍五入 #这三个函数的 ...

  4. Python 之 向上取整、向下取整以及四舍五入函数

    import math f = 11.2 print math.ceil(f) #向上取整 print math.floor(f) #向下取整 print round(f) #四舍五入 #这三个函数的 ...

  5. Java关于Math类的三个取整方法

    0x01 在java的Math类中有三个关于浮点数取整数的方法,分别是ceil (向上取整) floor(向下取整) round(四舍五入) 三个方法 0x02 ceil 向上取整,取整后总是比原来的 ...

  6. python向上取整 向下取整

    向上取整 ceil() 函数返回数字的向上取整整数,就是返回大于等于变量的最近的整数. ceil()是不能直接访问的,需要导入 math 模块. import math math.ceil( x ) ...

  7. python 向下取整,向上取整,四舍五入

    # python 向下取整 floor 向上取整ceil 四舍五入 round import math num=3.1415926 # 向上取整 print(math.ceil(num)) # 向下取 ...

  8. sql 中取整,四舍五入取整,向下取整,向上取整。

    SELECT round(52.45, 0) AS round4, round(52.54, 0) AS round5, round(52.45, 1) AS round41, round(52.54 ...

  9. c++ 向上取整和向下取整

    在c++ 中: ceil()表示向上取整 floor()表示向下取整 当然,这很显然对浮点数很好用. 但如果两个int类型的数想要向上取整呢? 我们用 (n-1)/m+1 来表示即可.

随机推荐

  1. Java 12 骚操作, switch居然还能这样玩!

    Java 13 都快要来了,12必须跟栈长学起! Java 13 即将发布,新特性必须抢先看! Java 12 中对 switch 的语法更友好了,建议大家看下栈长在Java技术栈微信公众号分享的&l ...

  2. CSS各类布局

    http://www.liquidapsive.com/ 1 静态布局(Static Layout)网页上的所有元素的尺寸一律使用px作为单位.特点:不管浏览器尺寸具体是多少,网页布局始终按照最初写代 ...

  3. 第12组 Beta冲刺(5/5)

    Header 队名:To Be Done 组长博客 作业博客 团队项目进行情况 燃尽图(组内共享) 展示Git当日代码/文档签入记录(组内共享) 注: 由于GitHub的免费范围内对多人开发存在较多限 ...

  4. mysql 面试题 查询出表中某字段的重复值

    users 表中有 两个字段  id 和 name 表数据大概如下: id       name 1       AAA 2       BBB 3       CCC 4       AAA 请写查 ...

  5. Single Cell Genomics Day: A Practical Workshop

    干货满满! Single Cell Genomics Day: A Practical Workshop

  6. 【E2EL5】A Year in Computer Vision中关于图像增强系列部分

    http://www.themtank.org/a-year-in-computer-vision 部分中文翻译汇总:https://blog.csdn.net/chengyq116/article/ ...

  7. 003-maven开发Java脚手架archrtype-技术点说明

    一.概述 二.技术点说明 2.1.项目结构 凡auto包或文件件,均会被代码生成器再次生成二修改 1.model层 po:BasePO基础类,统一了数据库的基础字段[数据库必须添加如下,与mybati ...

  8. 持久化机器学习模型(joblib方式)

    import numpy as np import matplotlib.pyplot as plt from sklearn.linear_model import LinearRegression ...

  9. Spring MVC -- JSP标准标签库(JSTL)

    JSP标准标签库(JavaServer Pages Standard Tag Library,JSTL)是一个JSP标签集合,它封装了JSP应用的通用核心功能.JSTL支持通用的.结构化的任务,比如迭 ...

  10. [LeetCode] 773. Sliding Puzzle 滑动拼图

    On a 2x3 board, there are 5 tiles represented by the integers 1 through 5, and an empty square repre ...