在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. Kali Linux之速会BEEF & XSS攻击

    beef 安装指南:https://github.com/beefproject/beef/wiki/Installation 升级ruby指南:https://www.cnblogs.com/waw ...

  2. Java_jdbc 基础笔记之七 数据库连接(方法升级)

    之前的更新方法 public static void update(String sql) { Connection conn = null; Statement statement = null; ...

  3. checkbox与label内的文字垂直居中的解决方案

    <label style="float:left;margin-top:5px;margin-left:10px;cursor:pointer"><input t ...

  4. [E2E_L9]Linux命令行上传文件到百度网盘

    百度有2TB 存储空间,在有第三方服务器的情况下,很多东西不需要下载到本地,可以直接使用服务转存,这非常好. 系统环境: Linux 系统 + Python 2.7 安装软件工具:[可能会要重复装] ...

  5. Python实现PIL将图片转成字符串

    # -*- coding: utf-8 -*- # author:baoshan from PIL import Image, ImageFilter codeLib = '''@#$%&?* ...

  6. rqalpha学习-2

    conf = default_config()deep_update(user_config(), conf)deep_update(project_config(), conf)   三种不同级别的 ...

  7. [LeetCode] 45. Jump Game II 跳跃游戏 II

    Given an array of non-negative integers, you are initially positioned at the first index of the arra ...

  8. [LeetCode] 117. Populating Next Right Pointers in Each Node II 每个节点的右向指针 II

    Follow up for problem "Populating Next Right Pointers in Each Node". What if the given tre ...

  9. [LeetCode] 325. Maximum Size Subarray Sum Equals k 和等于k的最长子数组

    Given an array nums and a target value k, find the maximum length of a subarray that sums to k. If t ...

  10. UE4 ios环境搭建备忘

    1.windows.mac安装证书 2.安装xcode .app -- 路径可以拖入 sudo gem install xcodeproj 3.错误处理 Setting up Mono Running ...