Ask coding questions

← Back to all posts
includes() in JavaScript
hah68 (1)

I need to find out if a number is has a decimal point or not. I was trying to use .includes()
But I am getting an error surrounding the (".")

hah68 (1)
tussiez (1435)

Best Solution

Use Number.isInteger(num). This returns true if the number does not have a decimal point, and false if it has one.

console.log(Number.isInteger(1.2)); // false
console.log(Number.isInteger(1)); // true
Coder100 (16802)

That's not valid syntax

this is not rust, you need parentheses on the expression.

if (numberString.includes('.')) {
} else {

please, add semicolons at the end of each statement. Thanks!

EpicGamer007 (1605)

do (numberString + "").includes('.') Currently, you are using a number, not a number String. or you can cover the 5.7 on line 8 with " to make it "5.7"