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
+10.7k SSL : The certificate is not trusted because no issuer chain was provided
+11.9k Golang : Convert int(year) to time.Time type
+12.3k Facebook PHP getUser() returns 0
+10.7k Golang : Surveillance with web camera and OpenCV
+9.7k Golang : How to unmarshal JSON inner/nested value and assign to specific struct?
+7.1k Golang : Load DSA public key from file example
+10.7k Golang : Simple file scaning and remove virus example
+8.6k Golang : Launch Mac OS X Preview (or other OS) application from your program example
+12.2k Generate salted password with OpenSSL example
+7.6k Golang : Generate Datamatrix barcode
+8.6k Golang : How to protect your source code from client, hosting company or hacker?
+7.1k Golang : Check from web if Go application is running or not