Determine if a number can be precisely represented in float/double format

c#, floating-point

Solution

You can use an online decimal to floating-point converter. For example, type in 1.577 and you get two indications that it is not exact:

1) The "Inexact" box is checked

2) It converts to 1.5769999999999999573674358543939888477325439453125 in double precision floating-point.

Contrast that to a number like 1.25, which prints as 1.25, and the "Inexact" box is NOT checked.

(That converter can also check single-precision numbers.)

Problem

How to determine if a number, for example 1.577, can be precisely represented in float or double format? It means it is real 1.577 not a 1.566999999999994324 etc. EDIT: I'm looking for a tool, where I can type a number and it will display double/float representation of it. So it's not only c# related question.

Original source

Related problems