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.pswp.cn/news/542066.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/542066.shtml
英文地址,請注明出處:http://en.pswp.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…