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.8k Golang : Drop cookie to visitor's browser and http.SetCookie() example
+4k Golang : What is StructTag and how to get StructTag's value?
+4.9k Golang : Takes a plural word and makes it singular
+7.7k Golang : interface - when and where to use examples
+8.4k Android Studio : Create custom icons for your application example
+4.6k Golang : How to fix html/template : "somefile" is undefined error?
+28.7k Golang : Integer is between a range
+3.3k JQuery : Calling a function inside Jquery(document) block
+4.1k Unix/Linux : How to test user agents blocked successfully ?
+12.4k nginx: [emerg] unknown directive "ssl"
+4.4k AWS S3 : Prevent Hotlinking policy
+4.1k Swift : Get substring with rangeOfString() function example