0

I have a float number that I would like to display in a string way.

E.g.

0.33 should be displayed as 1/3

0.5 should be displayed as 1/2

How can I do it in objective-c with no switch? (as I could have 3/4, 2/5 etc)

Dejell
  • 13,947
  • 40
  • 146
  • 229

1 Answers1

1

There's no objective-c way to do this, you'll have to implemente it yourself and find an algorightm.

What about trying combinations of A/B where A,B from 0 to 10, until you reach the number?

Antonio MG
  • 20,382
  • 3
  • 43
  • 62
  • 1
    Using "Continued Fractions", as in the answer to http://stackoverflow.com/questions/95727/how-to-convert-floats-to-human-readable-fractions (link given by Javi above), is *much* faster than trying all combinations. – Martin R Oct 30 '13 at 14:16
  • Thanks do you know if there is a library for it in objective-c? – Dejell Oct 30 '13 at 16:49