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
+8.3k Android Studio : Import third-party library or package into Gradle Scripts
+23.9k Golang : How to validate URL the right way
+5.5k Unix/Linux : Get reboot history or check when was the last reboot date
+8.5k Yum Error: no such table: packages
+32.4k Golang : Regular Expression for alphanumeric and underscore
+4.6k Nginx and PageSpeed build from source CentOS example
+26.4k Golang : How to check if a connection to database is still alive ?
+5.1k Unix/Linux/MacOSx : How to remove an environment variable ?
+6.9k Golang : Use modern ciphers only in secure connection
+8.7k Golang : Populate or initialize struct with values example
+40.7k Golang : How to count duplicate items in slice/array?
+7.1k Android Studio : How to detect camera, activate and capture example