I have this function to format monetary values:
function formatMonetary(v){
v = v.replace(/\D/g,"");
v = v.replace(/(\d{1})(\d{15})$/,"$1.$2");
v = v.replace(/(\d{1})(\d{11})$/,"$1.$2");
v = v.replace(/(\d{1})(\d{8})$/,"$1.$2");
v = v.replace(/(\d{1})(\d{5})$/,"$1.$2");
v = v.replace(/(\d{1})(\d{1,2})$/,"$1,$2");
return v;
}
When I input just a number 1
or 1,1
this function assume the value:
0,01
0,11
With a value alignment in the right way, is possible this function assume a value in the left way, when I input a number 1
or 1,1
:
1,00
1,10