-1

I have noticed that the parseFloat() function returns decimal numbers, but only up to 2 decimal places. Would it be possible for it to return the numbers with more decimal places? In case we need more precision

Libegria
  • 29
  • 3

1 Answers1

2

the parseFloat() function returns decimal numbers

No, it doesn't. It returns a binary (not decimal) floating point number.

only up to 2 decimal places

The number returned by parseFloat() has 24 significant digits. Binary digits, that is, also called “bits”. This is roughly equivalent to 7 decimal digits.

That being said, beware of Serial.print(). This function converts binary floating point numbers to decimal, and defaults to showing only two digits after the radix point. You can ask for more:

Serial.println(x, 6);  // display x with 6 digits after the radix point.

If you want to gain some basic understanding of how floating point numbers work, I recommend reading The Floating-Point Guide - What Every Programmer Should Know About Floating-Point Arithmetic.

Edgar Bonet
  • 45,094
  • 4
  • 42
  • 81