How to output fraction instead of decimal number?

后端 未结 13 2075
余生分开走
余生分开走 2020-12-01 21:59

In C++, When I calculate 2/3, it will output decimal values, how can I just get the original format (i.e.g 2/3) instead of 0.66666667

Thanks

13条回答
  •  庸人自扰
    2020-12-01 22:27

    You can store all your fraction's numerators and denominators as intergers. Integers have exact representations in binary.

提交回复
热议问题