I need to parseFloat this then to replace the dot with a comma:
sum="<?php echo substr($_tarif_membre,0,-2).'.'.substr($_tarif_membre,-2,2) ?>" * $('#tarif_membre').val()
total_total= sum.replace('.',',')
$('#total_total').val(sum)
if i dont multiply the php echoed variable by $('#tarif_membre').val() it will still show the result as a float:12.00 (as it is echoed from php) but if i multiply by $('#tarif_membre').val() the result will show 12, why? and why does the replace method does not work(i need to show comma separated values)
I think this is what you’re trying to do:
You can try it out here.
You should leave off the quotes since it’s a number, then
parseFloat()the#tarif_membre.val(), since that will be a string, then they key to mainain decimal places for money here is calling.toFixed()on that float, this will get you"12.00", a string. You can them replace the.for a,(for international formatting I’m guessing?) Then I’m sticking that result into the#total_total, though this piece I’m unsure on.For the other question, why doesn’t
.replace()work? It’s because in your code it was a float, not a string, and only strings have the replace method.