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
+13.2k Golang : Qt progress dialog example
+6.6k How to let Facebook Login button redirect to a particular URL ?
+42.9k Golang : Get hardware information such as disk, memory and CPU usage
+30.7k Golang : Calculate percentage change of two values
+4.8k Golang : Display packages names during compilation
+12.9k Golang : Convert(cast) int to int64
+9.5k Golang : Find correlation coefficient example
+5.2k Python : Delay with time.sleep() function example
+5.1k Golang : Get FX sentiment from website example
+8.8k Golang : Get curl -I or head data from URL example
+7.9k Golang : Routes multiplexer routing example with regular expression control
+7.5k Golang : How to execute code at certain day, hour and minute?