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
+14.4k Android Studio : Use image as AlertDialog title with custom layout example
+9.7k Golang : Find correlation coefficient example
+19.9k Golang : How to get time from unix nano example
+12.3k Golang : How to display image file or expose CSS, JS files from localhost?
+5.4k Golang : Get S3 or CloudFront object or file information
+29k Golang : Get first few and last few characters from string
+20.8k Golang : Underscore or snake_case to camel case example
+13k Golang : Calculate elapsed years or months since a date
+17k Golang : XML to JSON example
+15.2k Golang : Accurate and reliable decimal calculations
+5.8k CodeIgniter/PHP : Remove empty lines above RSS or ATOM xml tag
+10.1k Golang : Identifying Golang HTTP client request