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. jmeter 响应数据更换显示类型(json、html、text)

    .默认情况下是Text格式 2.修改为json格式显示

  2. Python 内置函数、作用域、闭包、递归

    一.内置函数如何使用 help()一下: 如想看min()咋用?在shell中:help(min) 二.部分内置函数 (一).排序:sorted() li = [(1, 2, 3, 4), (7, 8 ...

  3. [MongoDB]学习笔记--Linux 安装和运行MongoDB

    背景知识 MongoDB 是用C++写的, 开源的, NoSQL(Not Only SQL)文档数据库. 特点:high performance(高性能), high availability(高可靠 ...

  4. Permutation Descent Counts(递推)

    1968: Permutation Descent Counts Submit Page   Summary   Time Limit: 1 Sec     Memory Limit: 128 Mb  ...

  5. &#x编码转换成汉字

    import java.io.UnsupportedEncodingException; public class UnicodeDecoder { public static String esca ...

  6. MVC4学习笔记之--身份认证过滤器

    过滤器作为MVC模式中面向切面编程应用很广泛,例如身份验证,日志,异常,行为截取等.博客园里面的大神对应过滤器的介绍以及很多,MVC4中不同的过滤器也介绍得很清楚.FlyDragon  辉太 禁止吸烟 ...

  7. 0x07 MySQL 多表查询

    Some Content From——Egon's Blog http://www.cnblogs.com/linhaifeng/articles/7126847.html 一 准备表 准备表 #建表 ...

  8. (4.16)sql server迁移DB文件(同一DB内)

    SQL Server 修改数据库物理文件存在位置 关键词:迁移文件,迁移temp库(这怎么迁移呢,用方法2即可,需要重启实例) 三种均需要离线: 一共分为(1)脱机迁移和(2)在线迁移. (1)迁移方 ...

  9. Java并发—线程池框架Executor总结(转载)

    为什么引入Executor线程池框架 new Thread()的缺点 每次new Thread()耗费性能 调用new Thread()创建的线程缺乏管理,被称为野线程,而且可以无限制创建,之间相互竞 ...

  10. C#中的foreach和yield

    1. foreach C#编译器会把foreach语句转换为IEnumerable接口的方法和属性. foreach (Person p in persons) { Console.WriteLine ...