JavaScript中带有示例的Math.round()方法

JavaScript | Math.round()方法 (JavaScript | Math.round() Method)

Math.round() is a function in math library of JavaScript that is used to round the given number floating-point number to the nearest integer value.

Math.round()是JavaScript数学库中的函数,用于将给定数字浮点数舍入到最接近的整数值。

It works in a way that if the fraction part is smaller than 0.5 it rounds down (nearest integer small than it) and if the fraction part is greater than 0.5 it rounds up (nearest integer greater than it).

它的工作方式是,如果小数部分小于0.5,则四舍五入(最接近的整数小于它),如果小数部分大于0.5,则四舍五入(最近的整数大于它)。

Syntax:

句法:

    Math.round(value);

Parameter(s):

参数:

  • value – represent the value to be rounded.

    值 –表示要四舍五入的值。

Return value:

返回值:

The return type of this method is number, it returns the value which is nearest integer of the given value.

该方法的返回类型为number ,它返回的值是给定值的最接近整数。

Values accepted: Integer, floating-point, numeric string.

接受的值:整数,浮点数,数字字符串。

Invalid Values: non-numeric string, empty variable, empty array all will return NaN (Not a Number).

无效值:非数字字符串,空变量,空数组都将返回NaN(非数字)。

Browser support: Chrome, Internet asinlorer, Mozilla, Safari, Opera mini.

浏览器支持: Chrome,Internet代理,Mozilla,Safari,Opera mini。

Example 1: Valid values

示例1:有效值

console.log(Math.round(5.49999));
console.log(Math.round(-3.500121));
console.log(Math.round(0.990));
console.log(Math.round("-12.65"));

Output

输出量

5
-3
1
-11

Example 2: Invalid values

示例2:无效值

console.log(Math.round("Javascript"));

Output

输出量

NaN

翻译自: https://www.includehelp.com/code-snippets/math-round-method-with-example-in-javascript.aspx

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/542066.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

内部导线拉力测试_珠海后环回收试验机现金支付拉力试验机回收和谐温馨的环境...

珠海后环回收试验机现金支付拉力试验机回收和谐温馨的环境深圳富兴二手设备回收,拉力试验机回收,恒温恒湿箱回收,恒温恒湿试验箱回收,恒温恒湿培养箱回收,高低温试验箱回收,高低温冲击试验机回收&#xff0…

lvs负载均衡—ldirectord(DR模式的健康检查)

作用: 健康检查对企业而言也是由为重要,在生活中,有时候访问网页访问不到,就会跳出来一些图形告诉你访问失败,这就是健康检查的作用,当服务器都挂掉的时候,告诉你暂时访问不了。 ldirectord是后…

Reactor by Example--转

原文地址:https://www.infoq.com/articles/reactor-by-example Key takeaways Reactor is a reactive streams library targeting Java 8 and providing an Rx-conforming APIIt uses the same approach and philosophy as RxJava despite some API differencesIt i…

springboot项目后台运行关闭_springboot项目在服务器上部署过程(新手教程)

环境:服务器系统:ubuntu16jdkmysql工具 xshell6下载地址:https://www.netsarang.com/download/down_form.html?code622&downloadType0&licenseType1xftp6下载地址:https://www.netsarang.com/download/down_form.html?c…

如何在React Native中使用文本输入组件?

You know, an app becomes more authentic and professional when there is the interaction between the app and the user. 您知道,当应用程序与用户之间存在交互时,该应用程序将变得更加真实和专业。 The text input component in react-native brin…

lvs负载均衡—NAT模式

NAT模式原理图 Virtual Server via NAT : 用地址翻译实现虚拟服务器,地址转换器有能被外界访问到的合法IP地址,它修改来自专有网络的流出包的地址,外界看起来包是来自地址转换器本身,当外界包送到转换器时,它能判断出应该将包送到内部网的哪个节点。 优点是节省IP …

Django1.9开发博客06- 模板继承

模板继承就是网站的多个页面可以共享同一个页面布局或者是页面的某几个部分的内容。通过这种方式你就需要在每个页面复制粘贴同样的代码了。 如果你想改变页面某个公共部分,你不需要每个页面的去修改,只需要修改一个模板就行了,这样最大化复用…

乐高机器人亮剑_2500名选手大比拼 全球机器人广州从化“亮剑”

导读:国际机器人从化总动员学生自己编程、拼装的机器人既能像相扑手一样摔跤,又能像蜘蛛侠一样爬上爬下。还有智能垃圾处理系统,瞄准城市垃圾分类下的“痛点”。在2019RoboRAVE国际教育机器人大会全球总决赛的现场,只有想不到&…

python 编码问题_Python电源挑战| 竞争编码问题

python 编码问题Question: 题: A power function is that positive number that can be expressed as x^x i.e x raises to the power of x, where x is any positive number. You will be given an integer array A and you need to print if the elements of arr…

lvs负载均衡—高可用集群(keepalived)

基本概念: 什么是Keepalived呢,keepalived观其名可知,保持存活,在网络里面就是保持在线了,也就是所谓的高可用或热备,用来防止单点故障(单点故障是指一旦某一点出现故障就会导致整个系统架构的不可用)的发…

定期定量采购_企业常见的六种采购策略

注册职业采购经理CPPM考试网​www.apscppm.com对不起,我是采购合同生效的条件是什么?怎样制定谈判方案?如何在采购时让供应商听你的指挥!没做预算不能采购,应该作为企业采购管理的基本原则。编制现金预算就是要解决收入…

stringreader_Java StringReader markSupported()方法与示例

stringreaderStringReader类markSupported()方法 (StringReader Class markSupported() method) markSupported() method is available in java.io package. markSupported()方法在java.io包中可用。 markSupported() method is used to check whether this StringReader strea…

pacemaker+corosync实现集群管理

前言: 高可用集群,是指以减少服务中断(如因服务器宕机等引起的服务中断)时间为目的的服务器集群技术。简单的说,集群就是一组计算机,它们作为一个整体向用户提供一组网络资源。这些单个的计算机系统就是集群的节点。 …

分页导航的实现方法

这个导航是阅读了精通css这本书后做的demo&#xff0c;感觉以前写的真的是弱爆了 <!DOCTYPE html> <html lang"en"> <head><meta charset"UTF-8"><title>Document</title><style type"text/css">ol.n…

更换mysql_这些被你忽视的MySQL细节,可能会让你丢饭碗!

我们在 MySQL 入门篇主要介绍了基本的 SQL 命令、数据类型和函数&#xff0c;在具备以上知识后&#xff0c;你就可以进行 MySQL 的开发工作了&#xff0c;但是如果要成为一个合格的开发人员&#xff0c;你还要具备一些更高级的技能&#xff0c;下面我们就来探讨一下 MySQL 都需…

Java RandomAccessFile skipBytes()方法与示例

RandomAccessFile类skipBytes()方法 (RandomAccessFile Class skipBytes() method) skipBytes() method is available in java.io package. skipBytes()方法在java.io包中可用。 skipBytes() method is used to skip the given number of bytes in this file and possibly set …

rhcs集群套件—红帽6的高可用

含义及理解&#xff1a; RHCS是Red Hat Cluster Suite的缩写&#xff0c;也就是红帽子集群套件&#xff0c;RHCS是一个能够提供高可用性、高可靠性、负载均衡、存储共享且经济廉价的集群工具集合&#xff0c;&#xff0c;它将集群系统中三大集群架构&#xff08;高可用性集群、…

MapReduce二次排序

2019独角兽企业重金招聘Python工程师标准>>> 默认情况下&#xff0c;Map输出的结果会对Key进行默认的排序&#xff0c;但是有时候需要对Key排序的同时还需要对Value进行排序&#xff0c;这时候就要用到二次排序了。下面我们来说说二次排序 1、二次排序原理 我们把二…

数据有序_详解数据库插入性能优化:合并+事务+有序数据进行INSERT操作

概述对于一些数据量较大的系统&#xff0c;数据库面临的问题除了查询效率低下&#xff0c;还有就是数据入库时间长。特别像报表系统&#xff0c;每天花费在数据导入上的时间可能会长达几个小时或十几个小时之久。因此&#xff0c;优化数据库插入性能是很有意义的。其实最有效的…

Java ProcessBuilder environment()方法与示例

ProcessBuilder类的environment()方法 (ProcessBuilder Class environment() method) environment() method is available in java.lang package. environment()方法在java.lang包中可用。 environment() method is used to return Map interfaces of this process builder env…