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.5k Android Studio : Import third-party library or package into Gradle Scripts
+8.9k Golang : automatically figure out array length(size) with three dots
+6k Golang : Dealing with backquote
+6.1k Golang : Extract XML attribute data with attr field tag example
+15.5k Golang : rune literal not terminated error
+9.2k Golang : Temperatures conversion example
+26.7k Golang : Convert file content into array of bytes
+30.7k Golang : Download file example
+10.1k Golang : How to get quoted string into another string?
+6.1k Golang : Get Hokkien(福建话)/Min-nan(閩南語) Pronounciations
+5.9k Golang : Function as an argument type example
+27.6k PHP : Count number of JSON items/objects