How can I format an integer?
I need to visualize it as a price.
r = 100000;
comision = 10000;
totalp = r+comision;
document.getElementById("total").value = totalp;
Clearly the sum gives110000
Resultado que quiero obtener en el input
$110,000.00
You can obtain using NumberFormat directly, Through the
constuctor
, the values to pass arestyle
with a valuecurrency
that specifies that it will be a format ofdivisas
.currency
to specify the currency to use in this case it will be Dollars, or use external libraries such as Numeral.jsThe code that I leave you here, in addition to formatting the field according to any mask you place, also works as a calculator:
Using JQuery:
Adapted from: How to make my input text have a thousand and decimal separator in jquery?