0

I need value to return the full number to me: 249.87. But using parseFloat () or parseInt () always returns 249.

How can I get the full number back? Has as?

string = '249.87' 
value = parseFloat (string) 
console.log (value) // Return number 249.
Liam
  • 27,717
  • 28
  • 128
  • 190
  • `parseFloat()` does not do what you say it does, as you can immediately verify in your browser console. – Pointy Oct 16 '20 at 15:14
  • Can I convert this string to return me as the complete number I need? @Pointy – Matheus Nascimento Oct 16 '20 at 15:16
  • 1
    Yes, either `Number(yourString)` or `parseFloat(yourString)` will work. – Pointy Oct 16 '20 at 15:17
  • 1
    That code works fine. You can see in the snippet that it returns `249.87` not `249` like you state – Liam Oct 16 '20 at 15:23
  • 1
    I tested on my developer console and it does what you need string = '249.87' value = parseFloat (string) 249.87 console.log (value) 249.87 – Fermín Oct 16 '20 at 15:26
  • Sorry guys, in my representation I did it wrong ... Actually the string value = '249,87' ... That is, the problem is because the value of my string is a comma instead of a period – Matheus Nascimento Oct 16 '20 at 16:01

0 Answers0