JavaScript 中的 parseFloat() 函式


parseFloat() 函式接受兩個引數,第一個是要表示為數字的字串,另一個是要表示基數的數字,並返回給定基數的整數。

語法

語法如下

num.parseFloat('4524', 8);

示例

 即時演示

<html>
<head>
   <title>JavaScript Example</title>
</head>
<body>
   <script type="text/javascript">
      var result1 = parseFloat(Math.PI);
      document.write("Result: "+result1);
      document.write('<br>');
      var result2 = parseFloat("245.12@welcome");
      document.write("Result: "+result2);
      document.write('<br>');
      var result3 = parseFloat("11111100.010");
      document.write("Result: "+result3);
   </script>
</body>
</html>

輸出

Result: 3.141592653589793
Result: 245.12
Result: 11111100.01

更新於:2020 年 6 月 25 日

97 次瀏覽

開啟你的 職業 生涯

完成該課程即可獲得認證

開始
廣告
© . All rights reserved.