Why can't decimal numbers be represented exactly in binary?

前端 未结 20 3530
不知归路
不知归路 2020-11-21 05:15

There have been several questions posted to SO about floating-point representation. For example, the decimal number 0.1 doesn\'t have an exact binary representation, so it\'

20条回答
  •  时光取名叫无心
    2020-11-21 05:46

    As we have been discussing, in floating point arithmetic, the decimal 0.1 cannot be perfectly represented in binary.

    Floating point and integer representations provide grids or lattices for the numbers represented. As arithmetic is done, the results fall off the grid and have to be put back onto the grid by rounding. Example is 1/10 on a binary grid.

    If we use binary coded decimal representation as one gentleman suggested, would we be able to keep numbers on the grid?

提交回复
热议问题