0

There are many ways to limit the number of characters, for example here. In my case I want to limit the number of characters introduced after a dot.

I've tried to compute this inside maxlength:

myNumber = 43.143;

maxlength = (myNumber.Length - myNumber.IndexOf(".") - 1) <= 2;
Leo Messi
  • 5,157
  • 14
  • 63
  • 125

1 Answers1

0

If you are planning to display this variable. You can use .toFixed()

For example

example.textContent = myNumber.toFixed(2);

This would limit the number of decimal points to two on a display cancelling the need for editing it in your variable.

If this helped you please select this as the correct answer!

Cheers!

Dat Boi
  • 595
  • 3
  • 12
  • it doesn't work. for example, it modifies all values to have 2 digits after the dot, even if it doesn't have any – Leo Messi Apr 24 '19 at 12:16