I am creating a calculator, in which I need to give an option just like CASIO calculators, I mean I want to convert “1.5” into “3/2” or “2.5” into “5/2”
Explanation:
Textbox1.Text = 50
Textbox2.Text = 4
Dividing Textbo1.Text and Textbox2.Text
Calculate...........
Textbox3.text = 12.5 (Normaly)
but i dont need “12.5”
I want to Convert it into “25/2”
Please Friends Help me.
Thank you in advance.
What you want to do is weird but it’s achievable. This might not be the best solution but it can help you – convert this into a function so you can use it later
To make things easier, restrict to (n) decimal place(s) e.g. 1 d.p
For the example you gave above, 50/4 = 12.5
To achieve 25/2 then you’ll need this calculations
get the integer part = 12
get the decimap part = 0.5
get the value after(.) = 5
for 1 d.p, divider = 10, for 2 d.p divider=100, so we will use 10
so we have 5/10. You have to check if 10 is divisible by 5 until [No more?] = 1/2
then you have
Your (12 x (bottom) + top) / bottom
= (12×2+1)/2 = 25/2
there could be other alternatives to this steps…