: Hi,
:
: Im begginning and find a problem. I need to show fractions in my program to the user not as a real number. How should I define these variables ? Is there any algorithm that converts from real to rational numbers ? Or any way to showing it in the X/Y format to the user ?
:
:
Yes you can sort of convert to a rational number from a real. The routines for this depend on the language you are programming with. The routines are usually called "round" or "rnd". What you call rational numbers are the type "integer" or "int". The round routines just round a real number to an integer.
You can also output something like x/y. You need to convert the real values to strings(a textual type that stores a bunch of letters or characters in a "string"). You can just add stings together like this:
xasString + "/" + yAsString. Again, some things like the quote signs may be different for a different language. All you would have to do after that is draw that string on the screen or put it in a component.