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.9k Golang : Delay or limit HTTP requests example
+22.9k Golang : Call function from another package
+7.8k Golang : Apply Histogram Equalization to color images
+4.2k Python : Create Whois client or function example
+4.5k Javascript : Shuffle or randomize array example
+16.4k Golang : Read data from config file and assign to variables
+5.4k Grep : How to grep for strings inside binary data
+7.3k Android Studio : Import third-party library or package into Gradle Scripts
+13.1k Golang : How to get URL port?
+6.2k Golang : Example of custom handler for Gorilla's Path usage.
+9.6k Golang : Bubble sort example
+5.1k Golang : Debug with Godebug