Please find the fiddle http://jsfiddle.net/q2SgJ/5/
WANTS: {{val | number:2}} in \"input\"
-
I have extended the Tim's fiddle incase some one is looking for working solution
http://jsfiddle.net/q2SgJ/653/
modified the keypress event to retrieve the original typed value based on the cursor position
ele.bind('keypress',function(e){
var value = $(this).val();
var decimalPointPosition = value.indexOf(".");
if(!((e.charCode === 46) || (e.charCode > 47 && e.charCode <= 57)))
e.preventDefault();
else if (decimalPointPosition >= 0) {
var decimalCount = value.substring(decimalPointPosition + 1).length;
if ((decimalCount == 2 && $(this).prop("selectionStart") > decimalPointPosition)) {
e.preventDefault();
}
}
}