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
+25.1k Golang : Encrypt and decrypt data with AES crypto
+7.3k Android Studio : Image button and button example
+7.4k Golang : Add text to image and get OpenCV's X, Y co-ordinates example
+7.4k Golang : Implementing class(object-oriented programming style)
+5k Golang : How to write backslash in string?
+14.7k Golang : Read a file line by line
+9.2k Android Studio : Checkbox for user to select options example
+10.3k Golang : GTK Input dialog box examples
+19.6k Golang : Create and resolve(read) symbolic links
+5.1k Golang : Selection sort example
+10.6k Golang : convert(cast) float to string
+9.5k Golang : Interfacing with PayPal's IPN(Instant Payment Notification) example