0

I have a variable as amount.

  • If amount has value 10, then I should console log it as 'integer'
  • If amount has value 10.5, then I should console log it as 'float'
Aleksey Solovey
  • 4,153
  • 3
  • 15
  • 34
Raghul
  • 213
  • 1
  • 5
  • 9

1 Answers1

1

The most common way AFAIK is to use the remainder operator:

boolean isFloat = amount % 1 !== 0

This should work in all browsers

Alex
  • 2,953
  • 1
  • 27
  • 37