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
+5.1k Golang : Get a list of crosses(instruments) available to trade from Oanda account
+5.7k Javascript : How to refresh page with JQuery ?
+13.2k Golang : How to calculate the distance between two coordinates using Haversine formula
+7.5k Golang : Get YouTube playlist
+12.7k Golang : Transform comma separated string to slice example
+6.9k Golang : Normalize email to prevent multiple signups example
+11.5k Golang : Concatenate (combine) buffer data example
+5.2k Golang : Experimental Jawi programming language
+21.7k Golang : Encrypt and decrypt data with TripleDES
+9.4k Golang : Terminate-stay-resident or daemonize your program?
+9.3k Golang : How to check if a string with spaces in between is numeric?
+24.6k Golang : Time slice or date sort and reverse sort example