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.6k Golang : Check to see if *File is a file or directory
+6.7k Golang : Spell checking with ispell example
+17.2k Golang : Set up source IP address before making HTTP request
+13.6k Golang : Verify token from Google Authenticator App
+5.2k Golang : Constant and variable names in native language
+7.8k Golang : Set horizontal, vertical scroll bars policies and disable interaction on Qt image
+8k Golang : Regular Expression find string example
+18.2k Golang : Login and logout a user after password verification and redirect example
+18.6k Golang : How to remove certain lines from a file
+14.5k Golang : Get uploaded file name or access uploaded files
+9.1k Golang : GMail API create and send draft with simple upload attachment example
+23.3k Golang : simulate tail -f or read last line from log file example