lua math.floor 实现四舍五入:

lua 中的math.floor函数是向下取整函数。

  math.floor(5.123)  -- 5

  math.floor(5.523)   -- 5

用此特性实现四舍五入

  math.floor(5.123 + 0.5)  -- 5

  math.floor(5.523 + 0.5)  -- 6

也就是对math.floor函数的参数进行 “+ 0.5” 计算

math.floor实现四舍五入的更多相关文章

  1. Math函数的"四舍五入",Floor,Ceiling,Round的一些注意事项!

    1.Math.Round:四舍六入五取偶 引用内容 Math.Round(0.0) //0Math.Round(0.1) //0Math.Round(0.2) //0Math.Round(0.3) / ...

  2. Javascript Math.ceil()与Math.round()与Math.floor()区别

    Math.ceil()向上舍入 1 2 3 alert(Math.ceil(20.1)) //输出 21 alert(Math.ceil(20.5)) //输出 21 alert(Math.ceil( ...

  3. Java Math floor round ceil 函数

    public final class Math extends Object public static double floor(double a) public static long round ...

  4. js中Math.round、parseInt、Math.floor和Math.ceil小数取整总结

    Math.round.parseInt.Math.floor和Math.ceil 都可以返回一个整数,具体的区别请看下面的总结. 一.Math.round 作用:四舍五入,返回参数+0.5后,向下取整 ...

  5. Javascript -- Math.round()、Math.ceil()、Math.floor()、parseInt去小数取整总结

    一.Math.round() 作用:四舍五入返回整数.(返回参数+0.5后,向下取整) Math.round(5.57) //返回6 Math.round(2.4) //返回2 Math.round( ...

  6. Math.round()、Math.ceil()、Math.floor()与Math.random()的区别?

    Math.round(x) 四舍五入 加上0.5向下取整 Math.round(1.5) 2 Math.round(-11.5) -11 Math.round(-11.2) -10 Math.ceil ...

  7. JavaScript中的Math.ceil()、Math.round()、Math.floor()

    1. Math.ceil():向上取整(指取大于该浮点数的最小整数) 2. Math.round():四舍五入取整(注意:当该浮点数距离两端整数一样时,取较大的那个整数,如Math.round(-1. ...

  8. math ceil以及math floor,math:round

    ◎Math.ceil()执行向上舍入,即它总是将数值向上舍入为最接近的整数:◎Math.floor()执行向下舍入,即它总是将数值向下舍入为最接近的整数:◎Math.round()执行标准舍入,即它总 ...

  9. Math.floor(Math.random()*3+1)

    Math.random():获取0~1随机数 Math.floor() method rounds a number DOWNWARDS to the nearest integer, and ret ...

随机推荐

  1. X明X源面试题《二》

    一.解释5种访问修饰符答:public-访问不受限制.private-访问范围为它所属的类.protected-访问范围为它所属的类或从该类派生的类.internal-访问范围为当前程序集.prote ...

  2. poj2420(模拟退火大法好)

    // // main.cpp // poj2420 // // Created by 陈加寿 on 16/2/13. // Copyright © 2016年 chenhuan001. All rig ...

  3. rest规范 ; restful 风格; gradel介绍 ; idea安装 ;

    [说明]上午整理了一下心情:下午继续开始任务,了解了restful,知道了那个牛人的博士论文,下载了管理工具gradle,并且部署了环境:晚上安装了idea继承环境并且建了一个简单的gradle项目( ...

  4. 在执行save操作时候出现的诡异!

    情景:有一份excel数据需要导入到数据库中,想了想就写了一个导入excel的小功能. .............................准备使用时候,就开搞了,擦! 什么鬼??? 全程无报错 ...

  5. 比较运算符compareTo()、equals()、==之间的区别

    前言 首先再次强调hashcode (==)和equals的真正含义(我记得以前有人会说,equals是判断对象内容,hashcode是判断是否相等之类): equals:是否同一个对象实例.注意,是 ...

  6. 【转】Mysql之binlog日志说明及利用binlog日志恢复数据操作记录

    众所周知,binlog日志对于mysql数据库来说是十分重要的.在数据丢失的紧急情况下,我们往往会想到用binlog日志功能进行数据恢复(定时全备份+binlog日志恢复增量数据部分),化险为夷! 废 ...

  7. VS的编译选项

    转载下,对于VS的编译选项介绍蛮清楚的!! 1. 静态链接库.动态链接库.CRT.STL 我们要到一个函数,要么是需要该函数的源代码,要么是知道该函数的声明并有该函数的实现,这里的“实现”又分为静态链 ...

  8. setlocale()函数测试当前语言的两个程序

    http://www.cnblogs.com/cnyao/archive/2010/05/06/1729220.html setlocale()函数是用来配置地域信息的,原本以为这个也是windows ...

  9. UML初览(转)

    原文:UML初览 本章使用一个简单的例子对UML中所使用的概念和视图进行初览.本章的目的是要将高层UML概念组织成一系列较小的视图和图表来可视化说明这些概念,说明如何用各种不同的概念来描述一个系统以及 ...

  10. python模块学习(四)

    re模块 就其本质而言,正则表达式(或 RE)是一种小型的.高度专业化的编程语言,(在Python中)它内嵌在Python中,并通过 re 模块实现.正则表达式模式被编译成一系列的字节码,然后由用 C ...