zoukankan      html  css  js  c++  java
  • js笔记之Math random()、ceil()、floor()、round()

    JavaScript: The Definitive Guide, 4th Edition中对Math.ceil(),Math.floor()与Math.round()三个函数的定义。


    Math.random()

      返回 0 ~ 1 之间的随机数。    

    Math.ceil()

    ceil() 方法可对一个数进行上舍入。

    参数必须是一个数值。返回值大于等于 x,并且与它最接近的整数。

    Math.floor()

    floor() 方法可对一个数进行下舍入。

    参数可以是任意数值或表达式。返回值小于等于 x,且与 x 最接近的整数。

    Math.round()

    round() 方法可把一个数字舍入为最接近的整数

    参数必须是一个数值。返回值与 x 最接近的整数。

    document.writeln("Math.ceil(4.8992303)输出结果:"+Math.ceil(4.8992303)+"<br/>"); document.writeln("Math.floor(4.8992303)输出结果:"+Math.floor(4.8992303)+"<br/>"); document.writeln("Math.round(4.8992303)输出结果:"+Math.round(4.8992303)+"<br/><br/>"); document.writeln("Math.ceil(4.29993354)输出结果:"+Math.ceil(4.29993354)+"<br/>"); document.writeln("Math.floor(4.29993354)输出结果:"+Math.floor(4.29993354)+"<br/>"); document.writeln("Math.round(4.29993354)输出结果:"+Math.round(4.29993354));

    Math的Ceil,Floor,Round三个函数

  • 相关阅读:
    Epplus导出excel
    访问GitHub需要修改hosts
    如何将你的.Net Core程序部署成为服务
    生成雪花Id类
    文件操作帮助类
    工作流-WikeFlow
    《C语言进阶剖析》课程目录
    《C++深度解析》课程目录
    USB URB的status及其代表的意义
    数据结构优秀博文整理
  • 原文地址:https://www.cnblogs.com/maogu2/p/2836790.html
Copyright © 2011-2022 走看看