Baseline Widely available
Math.round()
颿°ã¯ã弿°ã¨ãã¦ä¸ããæ°ã忍äºå
¥ãã¦ããã£ã¨ãè¿ä¼¼ã®æ´æ°ãè¿ãã¾ãã
console.log(Math.round(0.9));
// Expected output: 1
console.log(Math.round(5.95), Math.round(5.5), Math.round(5.05));
// Expected output: 6 6 5
console.log(Math.round(-5.05), Math.round(-5.5), Math.round(-5.95));
// Expected output: -5 -5 -6
æ§æ 弿° è¿å¤
x
ã®å¤ããã£ã¨ãè¿ä¼¼ã®æ´æ°ã«åæ¨äºå
¥ããå¤ã
弿°ã®å°æ°é¨åã 0.5 以ä¸ã®å ´åããã®å¼æ°ã¯ã次ã«å¤§ããæ´æ°ã«åãä¸ãããã¾ãã弿°ã®å°æ°é¨åã 0.5 æªæºã®å ´åããã®å¼æ°ã¯ã次ã«å°ããæ´æ°ã«åãä¸ãããã¾ããå°æ°é¨åã 0.5 ã§ããå ´åã¯ãæ£ã®ç¡éå¤§ã®æ¹åã§æ¬¡ã®æ´æ°ã«ä¸¸ãããã¾ããããã¯å¤ãã®è¨èªã® round()
颿°ã¨ç°ãªããã¨ã«æ³¨æãã¦ãã ããããã®å ´åã¯ããã¦ãã0 ããé ãããæ¬¡ã®æ´æ°ã«ä¸¸ãããã¾ã (å°æ°é¨åã 0.5 ã§ããè² ã®å¤ã忍äºå
¥ããå ´åã«ãçµæãå¤ããã¾ã)ã
ã¡ã¢: ããã¯ãå¤ãã®è¨èªã® round()
颿°ã¨ã¯ç°ãªãã¾ãããããã®é¢æ°ã¯ãåå¢åãã¼ãããé¢ããæ¹åã¸ä¸¸ãããã¨ãå¤ããå°æ°é¨åãã¡ããã© 0.5 ã®è² æ°ã®å ´åã¯ç°ãªãçµæã¨ãªãã¾ãã
Math.round(x)
ã¯ã Math.floor(x + 0.5)
ã¨ã¾ã£ããåãã§ã¯ããã¾ããã x
ã -0ãã¾ã㯠-0.5 ⤠x < 0 ã®å ´åã Math.round(x)
㯠-0 ãè¿ãã䏿¹ã Math.floor(x + 0.5)
㯠0 ãè¿ãã¾ãããããããã®éããæ½å¨çãªç²¾åº¦ã¨ã©ã¼ãç¡è¦ããã°ã Math.round(x)
㨠Math.floor(x + 0.5)
ã¯ä¸è¬çã«åçã§ãã
round()
㯠Math
ãªãã¸ã§ã¯ãã®éçãªã¡ã½ãããªã®ã§ãèªãçæãã Math
ãªãã¸ã§ã¯ãã®ã¡ã½ããã¨ãã¦ã§ã¯ãªãã常ã«ãMath.round()
ã¨ãã¦ä½¿ç¨ããããã«ãã¦ãã ãã (Math
ã®ã³ã³ã¹ãã©ã¯ã¿ã¼ã¯ããã¾ãã)ã
Math.round(-Infinity); // -Infinity
Math.round(-20.51); // -21
Math.round(-20.5); // -20
Math.round(-0.1); // -0
Math.round(0); // 0
Math.round(20.49); // 20
Math.round(20.5); // 21
Math.round(42); // 42
Math.round(Infinity); // Infinity
仿§æ¸ ãã©ã¦ã¶ã¼ã®äºææ§ é¢é£æ
å ±
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4