Skip to main content
edited code block, added remark about comments in code
Source Link

Try this (see comments in code):

Try this: function fixInteger(el) { // this is element's value selector, you should use your own value = $(el).val(); if (value == '') { value = 0; } newValue = parseInt(value); // if new value is Nan (when input is a string with no integers in it) if (isNaN(newValue)) { value = 0; newValue = parseInt(value); } // apply new value to element $(el).val(newValue); } function fixPrice(el) { // this is element's value selector, you should use your own value = $(el).val(); if (value == '') { value = 0;   newValue = parseFloat(value).toFixed(2); } else {   newValue = parseFloat(value.replace(',', '.')).toFixed(2); }  // if new value is Nan (when input is a string with no integers in it) if (isNaN(newValue)) { value = 0; newValue = parseFloat(value).toFixed(2); } // apply new value to element $(el).val(newValue); } 
Try this: function fixInteger(el) { // this is element's value selector, you should use your own value = $(el).val(); if (value == '') { value = 0; } newValue = parseInt(value); // if new value is Nan (when input is a string with no integers in it) if (isNaN(newValue)) { value = 0; newValue = parseInt(value); } // apply new value to element $(el).val(newValue); } function fixPrice(el) { // this is element's value selector, you should use your own value = $(el).val(); if (value == '') { value = 0;   newValue = parseFloat(value).toFixed(2); } else {   newValue = parseFloat(value.replace(',', '.')).toFixed(2); }  // if new value is Nan (when input is a string with no integers in it) if (isNaN(newValue)) { value = 0; newValue = parseFloat(value).toFixed(2); } // apply new value to element $(el).val(newValue); } 

Try this (see comments in code):

function fixInteger(el) { // this is element's value selector, you should use your own value = $(el).val(); if (value == '') { value = 0; } newValue = parseInt(value); // if new value is Nan (when input is a string with no integers in it) if (isNaN(newValue)) { value = 0; newValue = parseInt(value); } // apply new value to element $(el).val(newValue); } function fixPrice(el) { // this is element's value selector, you should use your own value = $(el).val(); if (value == '') { value = 0; } newValue = parseFloat(value.replace(',', '.')).toFixed(2); // if new value is Nan (when input is a string with no integers in it) if (isNaN(newValue)) { value = 0; newValue = parseFloat(value).toFixed(2); } // apply new value to element $(el).val(newValue); } 
added 84 characters in body
Source Link
Try this: function fixInteger(el) { // this is element's value selector, you should use your own value = $(el).val(); if (value == '') { value = 0; } newValue = parseInt(value); // if new value is Nan (when input is a string with no integers in it) if (isNaN(newValue)) { value = 0; newValue = parseInt(value); } // apply new value to element $(el).val(newValue); } function fixPrice(el) { // this is element's value selector, you should use your own value = $(el).val(); if (value == '') { value = 0;   newValue = parseFloat(value).toFixed(2); } else {   newValue = parseFloat(value.replace(',', '.')).toFixed(2); }  // if new value is Nan (when input is a string with no integers in it) if (isNaN(newValue)) { value = 0; newValue = parseFloat(value).toFixed(2); } // apply new value to element $(el).val(newValue); } 
Try this: function fixInteger(el) { // this is element's value selector, you should use your own value = $(el).val(); if (value == '') { value = 0; } newValue = parseInt(value); // if new value is Nan (when input is a string with no integers in it) if (isNaN(newValue)) { value = 0; newValue = parseInt(value); } // apply new value to element $(el).val(newValue); } function fixPrice(el) { // this is element's value selector, you should use your own value = $(el).val(); if (value == '') { value = 0; } newValue = parseFloat(value.replace(',', '.')).toFixed(2); // if new value is Nan (when input is a string with no integers in it) if (isNaN(newValue)) { value = 0; newValue = parseFloat(value).toFixed(2); } // apply new value to element $(el).val(newValue); } 
Try this: function fixInteger(el) { // this is element's value selector, you should use your own value = $(el).val(); if (value == '') { value = 0; } newValue = parseInt(value); // if new value is Nan (when input is a string with no integers in it) if (isNaN(newValue)) { value = 0; newValue = parseInt(value); } // apply new value to element $(el).val(newValue); } function fixPrice(el) { // this is element's value selector, you should use your own value = $(el).val(); if (value == '') { value = 0;   newValue = parseFloat(value).toFixed(2); } else {   newValue = parseFloat(value.replace(',', '.')).toFixed(2); }  // if new value is Nan (when input is a string with no integers in it) if (isNaN(newValue)) { value = 0; newValue = parseFloat(value).toFixed(2); } // apply new value to element $(el).val(newValue); } 
Source Link

Try this: function fixInteger(el) { // this is element's value selector, you should use your own value = $(el).val(); if (value == '') { value = 0; } newValue = parseInt(value); // if new value is Nan (when input is a string with no integers in it) if (isNaN(newValue)) { value = 0; newValue = parseInt(value); } // apply new value to element $(el).val(newValue); } function fixPrice(el) { // this is element's value selector, you should use your own value = $(el).val(); if (value == '') { value = 0; } newValue = parseFloat(value.replace(',', '.')).toFixed(2); // if new value is Nan (when input is a string with no integers in it) if (isNaN(newValue)) { value = 0; newValue = parseFloat(value).toFixed(2); } // apply new value to element $(el).val(newValue); }