Prev Demo
JavaScript
>
Tofixed() Method
Next Demo
Write code here
J
|
B
|
A
<!DOCTYPE html> <html> <head> <title>Demo</title> </head> <body> <p>Click the below button to convert a number into a string <span style="background-color:yellow">without keeping any decimal</span>.</p> <input type="button" value="NoDecimal" onclick="Function()" /> <p id="myId"></p> <script> function Function() { var A = 2.74562; var R = A.toFixed(); document.getElementById("myId").innerHTML = R; } </script> <div>Click the below button to convert a number into a string by <span style="background-color:yellow">keeping only one decimal</span>.</div><br/> <input type="button" value="OneDecimal" onclick="myFunction()" /> <br/> <br/> <div id="ID"></div> <script> function myFunction() { var B = 2.79562; var S = B.toFixed(1) document.getElementById("ID").innerHTML = S; } </script> </body> </html>
Note: We DO NOT save your trial code in our database.
Output