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
+40.2k Golang : Convert string to array/slice
+6.8k Javascript : How to check a browser's Do Not Track status?
+4.7k Golang : Grab news article text and use NLP to get each paragraph's sentences
+7.6k Golang : Combine slices but preserve order example
+13.9k Golang : Force download file example
+4.8k nginx : force all pages to be SSL
+10.7k Golang : md5 hash of a string
+5.1k PageSpeed : Clear or flush cache on web server
+28.4k Golang : How to verify uploaded file is image or allowed file types
+10.5k CodeIgniter : Import Linkedin data
+11.7k Golang : http.Get example
+9.1k Golang : Wait and sync.WaitGroup example