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.1k Golang : Capture stdout of a child process and act according to the result
+3.6k Golang : Reclaim memory occupied by make() example
+8.8k Golang : How to check if your program is running in a terminal
+29.9k Golang : Display float in 2 decimal points and rounding up or down
+12k Golang : convert string or integer to big.Int type
+15.2k Golang : Read directory content with os.Open
+8.7k Golang : Post data with url.Values{}
+6.4k Golang : Use regular expression to get all upper case or lower case characters example
+10.8k Golang : Check if an integer is negative or positive
+5k Golang : Handling Yes No Quit query input
+20.4k Golang : Strings to lowercase and uppercase example
+19.7k Golang : Convert(cast) string to uint8 type and back to string