So I have a number var test_price = 94600
. I want to multiply it by the value a user types in an <input name="quantity" />
element, and to show that result in a <p id="sample">
element. This is self-describing: in the <p>
element it shows the total price (price * quantity
). I've managed to do that:
$('input[name="quantity"]').change(function () {
var test_price = 94600;
var quantity = $('input[name="quantity"]').val();
var price_without_thousands_separator = $('#sample').html(test_price * quantity);
});
Now I just want to add a period (.) after every three units to the #sample
paragraph. So if you have 1 as quantity it will show 94.600, if you have quantity=3 then 283.800, if quantity=8 then 756.800 and so on. Yes I know the usual tradition is to use commas, but here in my country we're used to read periods as thousands separators and commas as decimals (e.g. for us π = 3.14, not 3,14).
Happy holidays!!