Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> JavaScript

วิธีแปลงสตริง Scientific Notation ให้เป็นรูปแบบตัวเลข JavaScript ที่ถูกต้อง


เพื่อแปลงสตริงที่มี Scientific Notation ให้ใช้ฟังก์ชัน Number ส่งค่าเข้าไปในฟังก์ชันนี้

ตัวอย่าง

คุณสามารถลองรันโค้ดต่อไปนี้เพื่อแปลงสตริงให้เป็นรูปแบบตัวเลขที่ถูกต้อง:

Live Demo

<!DOCTYPE html> <html>    <body>       <script>          document.write("String with Scientific Notation converted below:<br>");          document.write(Number("7.53245683E7"));       </script>    </body> </html>

ผลลัพธ์

String with Scientific Notation converted below: 75324568.3