javascript 學習記錄

來源:互聯網
上載者:User

標籤:script   int   string   str   學習記錄   學習   方法   rip   解決方案   

javascript類型轉換過程中應該注意的情況
  1. 浮點數轉整型

    問題:
    使用parseInt轉換資料時,應該確定被轉換的資料不會出現0.0000006這樣的有效數在小數點的第7位及以上的資料,
    轉換的資料的方法parseInt會調用arg.toString()這會導致0.0000008轉換成8e-7,就會出現parseInt(0.0000008) //列印出:8這樣不想要的情況
    正確的解決方案:
    使用位元運算符

function convertToIn(num){ return num >>0; } convertToInt(-Math.PI) //>>-3 --- convertToInt(12.3424) //>>12 convertToInt(-0.000000000004) //>> 0

javascript 學習記錄

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.