I have a textbox that should always be an integer with a two decimal value. If the user does not add the decimals, I would like to use javascript to do it automatically.
I am using the code below, but often when I have a value with zeros, the value gets truncated when click on the textbox.
For example, I enter 1000 and the textbox updates to 1000.00 which is correct. When I revisit this text box and add an additional number, the zeros are truncated.
I believe this is an issue with parseFloat and I am looking for a workaround.
$(function () {
$("body").on("blur", "[id*=TextAmount]", function () {
$(this).val(parseFloat($(this).val(), 20).toFixed(2).replace(/(\d)(?=(\d{3})+(?!\d))/g, '$1').toString());
});
});