0

I want to allow user to enter values which are multiple of 0.10 like below - 0.10, 0.20, 0.30....1.00, 1.10, 1.20...1.90 etc

I was checking below validation when user entering value in text box

amount % 0.10 == 0

is it correct ? or i need to round reminder ?

Kalashir
  • 1,099
  • 4
  • 15
  • 38

1 Answers1

2

You can't use remainder (modulo) on anything but integers. In order to achieve something like that - you'll have to cast your numbers into integers.

you can do it by simply multiplying their value by 10, i.e:

1.2 x 10 = 12

then you can use javascripts Number.isInteger to verify it:

function validate(n) {
  let castedNumber = n*10;
  let isInteger = Number.isInteger(castedNumber);
  return isInteger;
}
silicakes
  • 6,364
  • 3
  • 28
  • 39