JavaScript The Solution

Jaime Serradell
PRO
Jaime Serradell
Pro Student 2,923 Points

Can I use parseInt instead parseFloat for this exercise? Is correct anyway?

The teacher use parseFloat to convert a number from a string. Is it correct to use parseInt instead parseFloat like the teacher uses?

2 Answers

Steven Parker
Steven Parker
140,537 Points

The correct conversion depends on what the number you are converting represents. For example, if the number is how many seats are at a table, "parseInt" would be the best choice. But if the number is the exact weight of a package in pounds, then "parseFloat" would be the right choice.

In the video, since the value is for generic math, "parseFloat" is a good choice because it applies the least constraint on the input value.