Possible Duplicate:
Convert decimal to fraction in Objective-C?
I’m trying to make an simple app for converting decimal form to fraction form. The decimal value is set to a UISlider´s value but how should I get the fraction in fraction form? Should I declare it with double or float and how should I tell the app to print it out in fraction form?
You want to return a fractional approximation from a real number? e.g. 0.3333 ~ “1/3”. You could try experimenting with this:
Prints
329/961to the console.Credits to David Eppstein, UC Irvine for the algorithm in C