2

I'm using jQuery ajax, and I'm trying to return the value "5.0000" from the php file and after, convert the value to float.

I'm sure that the value returning from the PHP file is "5.0000" because I used the alert() and document.write(). But when I convert this value using parseFloat(value); and use it inside alert, or document.write, it prints "NaN".

OBS: I just tested it in firefox, and it returned correctly, but in chrome it is still returning "NaN", why!?

Anyone, help me? I used all my day trying to fix this issue... :(

Thiago Yoithi
  • 495
  • 1
  • 6
  • 13

1 Answers1

0

Use an INFINITY constant to guard against NaN:

 parseFloat(value + Number.POSITIVE_INFINITY)

If the result is Infinity, value is probably ""

If the result is NaN, value is probably undefined

Paul Sweatte
  • 24,148
  • 7
  • 127
  • 265