1
How do I make my input stick to the decimals....
I need it to format at #total_buy
follows code
<script type="text/javascript">
$(document).ready(function() {
$("#evento_quantidade").change(function() {
var qtd = $(this).val();
var valor = $("#precoSoma").val();
var calculo = qtd * valor;
$("#total_compra").val(calculo);
});
String.prototype.formatMoney = function() {
var v = this;
if(v.indexOf('.') === -1) {
v = v.replace(/([\d]+)/, "$1,00");
}
v = v.replace(/([\d]+)\.([\d]{1})$/, "$1,$20");
v = v.replace(/([\d]+)\.([\d]{2})$/, "$1,$2");
v = v.replace(/([\d]+)([\d]{3}),([\d]{2})$/, "$1.$2,$3");
return v;
};
});
</script>
That’s right, but how do I apply it to my code?
– Betinho Silva
Look at this example : https://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_tofixed
– Monteiro
good Ek mto obg.... solved
– Betinho Silva