M Argus Chopin Gyver
M Argus Chopin Gyver

Reputation: 304

MaskMoney JQuery give wrong value

I have a form using this maskMoney Jquery PLugin https://github.com/plentz/jquery-maskmoney

and it's giving a wrong value when there's only 1 number behind the decimal symbol (Ex: If I want to write "300.50" it will show "30.05")

But when I try with 2 number behind decimal symbol, it show the correct value (ex : If I want to write "300.59", it show "300.59")

My code is only this

$('#product_price_1').maskMoney('mask',300.50);

Even with hardcoded value like above, it's still showing the false result ('30.05')

Any body have the same issue like this ?

Upvotes: 1

Views: 622

Answers (1)

Pedro
Pedro

Reputation: 21

I had this same problem, and I managed to solve a simple way, I hope it works for you.

let element =  document.getElementById('product_price_1');
let value = element.value;

value = parseFloat(valor.replace(',', '.')).toFixed(2).replace('.', ',');
document.getElementById('product_price_1').value = value;

Upvotes: 2

Related Questions