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
+6k Golang : Fibonacci number generator examples
+4.2k Golang : Get FX sentiment from website example
+3.9k Which content-type(MIME type) to use for JSON data
+8.9k Golang : Get current, epoch time and display by year, month and day
+8.9k Golang : Find and replace data in all files recursively
+6.7k Gogland : Where to put source code files in package directory for rookie
+10k Use systeminfo to find out installed Windows Hotfix(s) or updates
+6.9k Golang : Regular Expression find string example
+6.4k Golang : How to convert strange string to JSON with json.MarshalIndent
+7.3k Golang : Ackermann function example
+18.3k Golang : Archive directory with tar and gzip
+12k Golang : Linear algebra and matrix calculation example