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
+16.9k Golang : XML to JSON example
+16.6k Golang : Read integer from file into array
+5.2k JavaScript/JQuery : Redirect page examples
+34.5k Golang : How to stream file to client(browser) or write to http.ResponseWriter?
+11.4k Golang : Handle API query by curl with Gorilla Queries example
+13.4k Golang : Strings comparison
+4.3k Linux/MacOSX : Search and delete files by extension
+9.2k Golang : How to get garbage collection data?
+4.6k Facebook : How to place save to Facebook button on your website
+6.7k Android Studio : Hello World example
+17.6k How to enable MariaDB/MySQL logs ?
+7.7k Golang : Generate human readable password