Baseline Widely available
Math.trunc()
颿°ã¯ã弿°ã¨ãã¦ä¸ããæ°ã®å°æ°é¨ã®æ¡ãåãé¤ããã¨ã«ãã£ã¦æ´æ°é¨ãè¿ãã¾ãã
console.log(Math.trunc(13.37));
// Expected output: 13
console.log(Math.trunc(42.84));
// Expected output: 42
console.log(Math.trunc(0.123));
// Expected output: 0
console.log(Math.trunc(-0.123));
// Expected output: -0
æ§æ 弿° è¿å¤
x
ã®æ´æ°é¨ã§ãã
ä»ã® 3 ã¤ã® Math
ã¡ã½ãããMath.floor()
ãMath.ceil()
ãMath.round()
ã¨ã¯ç°ãªãã Math.trunc()
ã®åä½ã¯é常ã«ã·ã³ãã«ã§åãããããã§ãã弿°ãæ£ã®æ°ã¾ãã¯è² ã®æ°ã§ãããã«é¢ãããããã å°æ°ç¹ã¨ãã以éã«ããæ°åãåãæ¨ã¦ã¾ãã
trunc()
㯠Math
ãªãã¸ã§ã¯ãã®éçãªã¡ã½ãããªã®ã§ãèªãçæãã Math
ãªãã¸ã§ã¯ãã®ã¡ã½ããã¨ãã¦ã§ã¯ãªãã常ã«ãMath.trunc()
ã¨ãã¦ä½¿ç¨ãã¦ãã ãã (Math
ãªãã¸ã§ã¯ãã«ã¯ã³ã³ã¹ãã©ã¯ã¿ãããã¾ãã)ã
Math.trunc(-Infinity); // -Infinity
Math.trunc("-1.123"); // -1
Math.trunc(-0.123); // -0
Math.trunc(-0); // -0
Math.trunc(0); // 0
Math.trunc(0.123); // 0
Math.trunc(13.37); // 13
Math.trunc(42.84); // 42
Math.trunc(Infinity); // Infinity
ãããåä½ã® no-op ã使ã£ãæ°å¤ã®åãæ¨ã¦
è¦å: ç¡è¦ã§ããªãã¨ãã¸ã±ã¼ã¹ãããããããã㯠Math.trunc()
ã®ããªãã£ã«ã«ã¯ãªãã¾ããã
ãããæ¼ç®ã¯ãªãã©ã³ãã 32 ãããæ´æ°ã«å¤æãã¾ããä¸è¬çãªãã¯ããã¯ã¯ä»¥ä¸ã®éãã§ãã
const original = 3.14;
const truncated1 = ~~original; // äºéå¦å®
const truncated2 = original & -1; // Bitwise AND with -1
const truncated3 = original | 0; // Bitwise OR with 0
const truncated4 = original ^ 0; // Bitwise XOR with 0
const truncated5 = original >> 0; // Bitwise shifting by 0
ããã¯æ¬è³ªçã« toInt32
ã§ããã Math.trunc
ã¨ã¯ç°ãªããã¨ã«æ³¨æãã¦ãã ãããå¤ã -231 - 1 < value
< 231 (-2147483649 < value
< 2147483648) ãæºãããªãå ´åã夿ããªã¼ãã¼ããã¼ãã¦ãã¾ãã¾ãã
const a = ~~2147483648; // -2147483648
const b = ~~-2147483649; // 2147483647
const c = ~~4294967296; // 0
Math.trunc()
ã®ä»£ç¨ã¨ã㦠~~
ã使ãã®ã¯ãå
¥åã®ç¯å²ã 32 ãããæ´æ°ã®ç¯å²ã«åã¾ã£ã¦ããã¨ç¢ºä¿¡ã§ããå ´åã ãã«ãã¦ãã ããã
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