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
+7.8k Golang : Reverse text lines or flip line order example
+26.6k Golang : Convert CSV data to JSON format and save to file
+7.7k Golang : HTTP Server Example
+17.1k How to enable MariaDB/MySQL logs ?
+4.7k Golang : Print instead of building pyramids
+11.8k Golang : Get month name from date example
+5.4k Golang : Struct field tags and what is their purpose?
+13.4k Golang : convert rune to unicode hexadecimal value and back to rune character
+8.7k Golang : Generate EAN barcode
+26.8k Golang : Convert integer to binary, octal, hexadecimal and back to integer
+18.3k Golang : Delete duplicate items from a slice/array
+16.2k Golang : Gzip file example