SQL PHP HTML ASP JavaScript articles and free scripts to download
 

toFixed Math function to format number

We can use toFixed function in math to format a number upto required decimal places. The value we get is after rounding the number upto the decimal place required. This function is frequently used to format currency, marks etc.

Here is the syntax.
my_val.toFixed(4) 
my_val is the variable which stores the number. Here we are formatting the number upto 4 decimal places.

Let us try with some examples with different number values.
var my_val=11.257;
document.write (my_val.toFixed(2)); // output 11.26
document.write ("<br>----<br>");

var my_val=11.25;
document.write (my_val.toFixed(1)); // output 11.3 
document.write ("<br>----<br>");

var my_val=11.978;
document.write (my_val.toFixed(4)); // output 11.9780
document.write ("<br>----<br>");
You can read the php math number format

Found anything wrong or wants to improve the code by adding more features? Post your short comment here or use the Forum



Post Comment This is for short comments only. Use the forum for more discussions.
Name
Email( not to be displayed)Privacy Policy
1+2=This is to prevent automatic submission by spammers. Please enter the result of the sum as asked

Join Our Email List
Email:  
For Email Newsletters you can trust
Math functions
HTML . MySQL. PHP. JavaScript. ASP. Photoshop. Articles. FORUM Contact us

©2000-2013 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer