![](/img/trans.png)
[英]How can I use Number() to convert a string to number without losing the decimal points?
[英]How would I use js to convert a decimal to number to a hex string?
十進制輸入: 76561198291043943
十六進制輸出: 110000113b74660
十六進制預期輸出: 110000113b74667
出於某種原因,當我使用以下代碼段並執行它時,不會出現預期的結果,但是當我使用https://www.binaryhexconverter.com/decimal-to-hex-converter將十進制數轉換為十六進制時字符串,我得到了預期的輸出。
console.log(Number(76561198291043943).toString(16))
76561198291043943
大於Number.MAX_SAFE_INTEGER
。
改用BigInt
:
console.log(BigInt("76561198291043943").toString(16))
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.