# Floating Point Input [duplicate]

In this challenge: rounding numbers.

Most answers use floating point numbers, which means that many potential input values are impossible due to the limited precision.

For example, the inputs .02675 and 4. In this challenge, that would mean rounding .02675 to 4 decimal places, which should result in .0268.
However, 0.02675 can't be represented exactly in the common floating point formats, and it's actually stored as .02674999..., which rounds to .0267.

Are these answers are invalid because they can't accept all the potential input values?

• Possible duplicate, though a strong consensus wasn't reached there. – Kamil Drakari Jun 7 '18 at 17:56

If a language/program can handle the numbers as accurate decimal numbers then allow this. That means that it's OK to return 0.15 as 0.2 if only one decimal number is required.
If a language/program can't handle the numbers as accurate decimal numbers, then allow for the default behavior. That means that it's OK to return 0.15 as 0.1 if only one decimal is required, since it's floating point value is 0.14999...
In the specific challenge you linked to, both 0.0268 and 0.0267 would be OK. However, rounding 0.25 to 0.2 would not be OK, since 0.25 can be accurately represented using floats.