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
+9.8k Golang : Resumable upload to Google Drive(RESTful) example
+15.3k Golang : Get timezone offset from date or timestamp
+13.2k Golang : Handle or parse date string with Z suffix(RFC3339) example
+7.5k Golang : Get YouTube playlist
+4.5k Java : Generate multiplication table example
+7.9k Golang : Getting Echo framework StartAutoTLS to work
+9.4k Golang : How to protect your source code from client, hosting company or hacker?
+12.1k Golang : Sort and reverse sort a slice of runes
+11.3k Golang : Intercept and process UNIX signals example
+7.2k Golang : Dealing with postal or zip code example
+5.8k Linux/Unix/PHP : Restart PHP-FPM
+16.1k Golang : How to reverse elements order in map ?