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
+32.7k Golang : convert(cast) bytes to string
+37.8k Golang : Remove dashes(or any character) from string
+27.8k Golang : Save map/struct to JSON or XML file
+12.4k Golang : How to get year, month and day?
+19.4k Golang : Convert PNG transparent background image to JPG or JPEG image
+2.2k Golang : Switch Redis database redis.NewClient
+53.2k Golang : Unmarshal JSON from http response
+9.7k Golang : Fix - does not implement sort.Interface (missing Len method)
+12.8k Elastic Search : Mapping date format and sort by date
+26.4k Golang : Move file to another directory
+6.8k Golang : Get today's weekday name and calculate target day distance example
+6.6k Setting $GOPATH environment variable for Unix/Linux and Windows