0

var string = -526.56;
var string1 = "-526.56";

console.log("string " + string.length)
console.log("string " + string)
console.log("string1 " + string1.length)
console.log("string1 " + string1)

I am getting the length of a float but it is returning undefined. What is the correct way to get the length of a float? Basically i want to make sure that the float is has value. At first I compare it to greater than 0 but then i am getting negative values so I decided to get the length but also it failed the if statement because it is returning undefined.

Martin
  • 365
  • 4
  • 7
  • 22

1 Answers1

0
var string = -526.56;
console.log("string " + (string+"").length);

Or you can use like this string.toString()

RonyLoud
  • 2,408
  • 2
  • 20
  • 25
cbalakus
  • 620
  • 7
  • 15