如何返回當前數字的字串值版本?


toLocaleString() 方法返回當前數字的字串值版本,其格式可能因瀏覽器的本地設定而異。

示例

你可以嘗試執行以下程式碼以返回一個字串值版本 −

<html>
   <head>
      <title>JavaScript toLocaleString() Method </title>
   </head>

   <body>
      <script>
         var num = new Number(150.1234);
         document.write( num.toLocaleString());
      </script>
   </body>
</html>

更新於: 23-Jun-2020

176 次瀏覽

開啟你的 職業生涯

透過完成課程獲得認證

開始學習
廣告
© . All rights reserved.