JavaScript : Rounding number to decimal formats to display currency
Tags : javascript rounding tofixed decimal-points currency-money
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
Tags : javascript rounding tofixed decimal-points currency-money
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
+1.4k Golang : Convert Chinese UTF8 characters to Pin Yin
+2.2k Golang : Convert string slice to struct and access with reflect example
+1.6k Golang : Word limiter example
+5.3k Golang : syscall.Socket example
+7.4k Golang : Convert date format and separator yyyy-mm-dd to dd-mm-yyyy
+9.6k Golang : Generate universally unique identifier(UUID) example
+1.5k Get website traffic ranking with Similar Web or Alexa
+9.3k Golang : Read, Write(Create) and Delete Cookie example
+6.7k Golang : convert rune to integer value
+2.3k Golang : Generate Codabar
+2k Golang : Get final or effective URL with Request.URL example