{"id":1224,"date":"2022-11-17T18:36:39","date_gmt":"2022-11-17T10:36:39","guid":{"rendered":"https:\/\/fdream.net\/blog\/?p=1224"},"modified":"2022-11-17T18:36:39","modified_gmt":"2022-11-17T10:36:39","slug":"%e4%b8%ba%e4%bb%80%e4%b9%88parseint0-0000007%e7%bb%93%e6%9e%9c%e4%b8%ba7%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fdream.net\/blog\/article\/1224","title":{"rendered":"\u4e3a\u4ec0\u4e48parseInt(0.0000007)\u7ed3\u679c\u4e3a7\uff1f"},"content":{"rendered":"\n<p>\u4e00\u4e2a\u770b\u4f3c\u5947\u602a\u7684\u95ee\u9898\uff0c\u6b63\u5e38\u6211\u4eec\u9884\u671f\u8fd9\u4e2a\u7ed3\u679c\u5e94\u8be5\u662f0\u624d\u5bf9\uff0c\u7ed3\u679c\u5374\u662f7\uff0c\u4ee4\u4eba\u610f\u5916\u3002\u53c2\u8003<a href=\"https:\/\/262.ecma-international.org\/12.0\/#sec-parseint-string-radix\" target=\"_blank\" rel=\"noreferrer noopener\">ECMAScript\u6807\u51c6\u91cc\u9762\u7684\u63cf\u8ff0<\/a>\uff1a<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>The\u00a0<code>parseInt<\/code>\u00a0function produces an\u00a0<a href=\"https:\/\/262.ecma-international.org\/12.0\/#integral-number\">integral Number<\/a>\u00a0dictated by interpretation of the contents of the\u00a0<var>string<\/var>\u00a0argument according to the specified\u00a0<var>radix<\/var>. Leading white space in\u00a0<var>string<\/var>\u00a0is ignored. If\u00a0<var>radix<\/var>\u00a0is\u00a0undefined\u00a0or 0, it is assumed to be 10 except when the number begins with the code unit pairs\u00a0<code>0x<\/code>\u00a0or\u00a0<code>0X<\/code>, in which case a radix of 16 is assumed. If\u00a0<var>radix<\/var>\u00a0is 16, the number may also optionally begin with the code unit pairs\u00a0<code>0x<\/code>\u00a0or\u00a0<code>0X<\/code>.<\/p>\n<\/blockquote>\n\n\n\n<p><code>parseInt<\/code>\u8fd9\u4e2a\u51fd\u6570\u63a5\u53d7\u7684\u662f<code>string<\/code>\u7c7b\u578b\u7684\u53c2\u6570\uff0c\u6240\u4ee5\u5728\u8fd9\u91cc\u7b2c\u4e00\u6b65\u4f1a\u628a\u8fd9\u4e2a\u5c0f\u65700.0000007\u8f6c\u6362\u4e3a\u5b57\u7b26\u4e32\u3002<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>The&nbsp;<code>parseInt<\/code>&nbsp;function is the&nbsp;<dfn>%parseInt%<\/dfn>&nbsp;intrinsic object. When the&nbsp;<code>parseInt<\/code>&nbsp;function is called, the following steps are taken:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>1.&nbsp;1.&nbsp;Let&nbsp;<var>inputString<\/var>&nbsp;be ?&nbsp;<a href=\"https:\/\/262.ecma-international.org\/12.0\/#sec-tostring\">ToString<\/a>(<var>string<\/var>).<\/li>\n\n\n\n<li>2.&nbsp;2.&nbsp;Let&nbsp;<var>S<\/var>&nbsp;be !&nbsp;<a href=\"https:\/\/262.ecma-international.org\/12.0\/#sec-trimstring\">TrimString<\/a>(<var>inputString<\/var>,&nbsp;start).<\/li>\n<\/ol>\n<\/blockquote>\n\n\n\n<p>\u5728\u901a\u5e38\u7684\u60c5\u51b5\u4e0b\uff0c\u5c0f\u6570\u8f6c\u6362\u4e3a\u5b57\u7b26\u4e32\u662f\u8fd9\u6837\u7684\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>String(0.7);      \/\/ => '0.7'\nString(0.07);     \/\/ => '0.07'\nString(0.007);    \/\/ => '0.007'\nString(0.0007);   \/\/ => '0.0007' \nString(0.00007);  \/\/ => '0.00007'\nString(0.000007); \/\/ => '0.000007'<\/code><\/pre>\n\n\n\n<p>\u73b0\u5728\u95ee\u9898\u6765\u4e86\uff0c0.0000007\u8f6c\u6362\u4e3a\u5b57\u7b26\u4e32\u4e0d\u662f\u4e0a\u9762\u8fd9\u6837\u7684\uff0c\u800c\u662f\u4e0b\u9762\u8fd9\u6837\u7684\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>String(0.0000007); \/\/ => '7e-7'<\/code><\/pre>\n\n\n\n<p>\u6240\u4ee5\u63a5\u4e0b\u6765\u8fd9\u4e2a\u8868\u8fbe\u5f0f\u8f6c\u6362\u4e3aparseInt(&#8216;7e-7&#8217;)\uff0c\u5728\u6b64\u79cd\u60c5\u51b5\u4e0b\uff0cECMAScript\u7684\u63cf\u8ff0\u662f\u8fd9\u6837\u7684\uff1a<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p><code>parseInt<\/code>\u00a0may interpret only a leading portion of\u00a0<var>string<\/var>\u00a0as an\u00a0<a href=\"https:\/\/262.ecma-international.org\/12.0\/#integer\">integer<\/a>\u00a0value; it ignores any code units that cannot be interpreted as part of the notation of an\u00a0<a href=\"https:\/\/262.ecma-international.org\/12.0\/#integer\">integer<\/a>, and no indication is given that any such code units were ignored.<\/p>\n<\/blockquote>\n\n\n\n<p>\u8f6c\u6362\u4e3a\u6574\u6570\u65f6\u53ea\u53d6\u5b57\u7b26\u4e32\u524d\u9762\u7684\u6570\u5b57\u90e8\u5206\uff0c\u975e\u6570\u5b57\u5f00\u59cb\u7684\u5b57\u7b26\u53ca\u540e\u9762\u7684\u90fd\u4f1a\u88ab\u5ffd\u7565\u3002\u6240\u4ee5\u5728\u8fd9\u4e2a\u60c5\u51b5\u4e0b\u4f1a\u8fd4\u56de7\uff0c\u5176\u4ed6\u7684\u90e8\u5206\u4f1a\u5ffd\u7565\u3002<\/p>\n\n\n\n<p>\u56e0\u6b64\u5efa\u8bae\u5927\u5bb6\uff0c\u8bf7\u786e\u4fdd\u53c2\u6570\u662f\u5b57\u7b26\u4e32\u4e4b\u540e\u518d\u4f7f\u7528parseInt\uff0c\u5426\u5219\u8bf7\u4f7f\u7528<code>Math.round<\/code>\u3001<code>Math.floor<\/code>\u6216\u8005<code>Math.ceil<\/code>\u65b9\u6cd5\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e00\u4e2a\u770b\u4f3c\u5947\u602a\u7684\u95ee\u9898\uff0c\u6b63\u5e38\u6211\u4eec\u9884\u671f\u8fd9\u4e2a\u7ed3\u679c\u5e94\u8be5\u662f0\u624d\u5bf9\uff0c\u7ed3\u679c\u5374\u662f7\uff0c\u4ee4\u4eba\u610f\u5916\u3002\u53c2\u8003ECMAScript\u6807\u51c6\u91cc\u9762\u7684\u63cf\u8ff0\uff1a The\u00a0parseInt\u00a0function produces an\u00a0integral Number\u00a0dictated by interpretation of the contents of the\u00a0string\u00a0argument according to the specified\u00a0radix. Leading white space in\u00a0string\u00a0is ignored. If\u00a0radix\u00a0is\u00a0undefined\u00a0or 0, it is assumed to be 10 except when the number begins with the code unit pairs\u00a00x\u00a0or\u00a00X, in which case a radix of 16 is assumed. If\u00a0radix\u00a0is 16, the number may also optionally &hellip; <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[104],"class_list":["post-1224","post","type-post","status-publish","format-standard","hentry","category-coding","tag-JavaScript"],"views":378,"_links":{"self":[{"href":"https:\/\/fdream.net\/blog\/wp-json\/wp\/v2\/posts\/1224","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fdream.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fdream.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fdream.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fdream.net\/blog\/wp-json\/wp\/v2\/comments?post=1224"}],"version-history":[{"count":0,"href":"https:\/\/fdream.net\/blog\/wp-json\/wp\/v2\/posts\/1224\/revisions"}],"wp:attachment":[{"href":"https:\/\/fdream.net\/blog\/wp-json\/wp\/v2\/media?parent=1224"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fdream.net\/blog\/wp-json\/wp\/v2\/categories?post=1224"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fdream.net\/blog\/wp-json\/wp\/v2\/tags?post=1224"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}