It's not difficult at all: 12.3 is just 12
3/
10 and 12.5 is just 12
5/
10
It's if you want it as a irreducible fraction that it gets more complex, i.e. 12.3 is just 12
3/
10 but 12.5 is 12
1/
2
This is your homework, so I'll give you no code, but see here:
Irreducible fraction - Wikipedia[
^] - it may give you some ideas.