Converting a float into a string fraction representation

后端 未结 6 768
一整个雨季
一整个雨季 2021-01-17 20:23

In Java, I am trying to find a way to convert a float number into a fraction string. For example:

float num = 1.33333;
String numStr = Convert(num); // Shoul         


        
6条回答
  •  别那么骄傲
    2021-01-17 20:34

    Look into chain fractions. This allows you to determine denominator and fraction within a given accuracy.

    For Pi you can get 22/7 or 355/113 depending on when you choose to stop.

提交回复
热议问题