JavaScript : Rounding number to decimal formats to display currency
Was looking for ways to round up float numbers to 2 decimal points and also to display currency with Javascript. Below is just a code fragment in JavaScript on how to properly format integer to display currency or money and for rounding up to 2 decimal points.
var money = 12.3456789;
var roundedMoney = money.toFixed(2); // round to 2 decimal points
alert("Before : $" + money)
alert("After : $" + roundedMoney)
Play at : http://codepen.io/anon/pen/bdzJVY
Happy coding!
See also : Javascript : Generate random key with specific length
By Adam Ng
IF you gain some knowledge or the information here solved your programming problem. Please consider donating to the less fortunate or some charities that you like. Apart from donation, planting trees, volunteering or reducing your carbon footprint will be great too.
Advertisement
Tutorials
+8.7k Golang : Convert(cast) []byte to io.Reader type
+11.2k Golang : Roll the dice example
+12k Golang : How to parse plain email text and process email header?
+5.9k Golang : List all packages and search for certain package
+16.6k Golang : File path independent of Operating System
+6.2k Fix ERROR 2003 (HY000): Can't connect to MySQL server on 'IP address' (111)
+20.7k Nginx + FastCGI + Go Setup.
+18.4k Golang : Get path name to current directory or folder
+5.9k Javascript : How to replace HTML inside <div>?
+8.7k Golang : Add text to image and get OpenCV's X, Y co-ordinates example
+10.8k Golang : Underscore string example
+6.5k CodeIgniter : form input set_value cause " to become & quot