-3

I stuck with input mask format for decimal 3 digits.

For example, if user input 1 then it should be automatically formatted to 0.001 if user input 11 then it should be 0.011 means input digit start from right to left but I need to maintain 3 digits after "." and before the decimal point, the user can input infinite value. means if user input 11111 than it should be 11.111 and if user input 111111 than it should be 111.111.

Thanks In Advance.

Gufran Hasan
  • 8,910
  • 7
  • 38
  • 51

1 Answers1

1

If you want to format number in decimal for 1,2,3 etc. digits. Please use toFixed() function as:

var input =  111;
input = input.toFixed(3);
console.log(input);
output: 111.000

But here your requirement is different. As Dean said, You can multiply by 0.001 to the given number as:

var input = 111;
input = input*0.001;
console.log(input);
output: 0.111;
Gufran Hasan
  • 8,910
  • 7
  • 38
  • 51