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
+24.3k Golang : How to read integer value from standard input ?
+10.1k Google Maps URL parameters configuration
+7.3k Golang : Metaprogramming example of wrapping a function
+22.1k Find and replace a character in a string in Go
+15.8k Golang : Find file size(disk usage) with filepath.Walk
+4.6k Golang : What is StructTag and how to get StructTag's value?
+18.4k Golang : Determine if directory is empty with os.File.Readdir() function
+11.7k Golang : Convert int(year) to time.Time type
+12.8k Golang : How to convert a number to words
+8k Golang : Find the length of big.Int variable example
+9.3k Golang : Convert file unix timestamp to UTC time example
+8.9k Golang : Check if user agent is a robot or crawler example