0

How to calculate with a fractional number proceeded after 0?

I am trying to solve a problem and I know we can't divide or do any Arithmetic with anything that ceils to zero. Eg: 6/(23/45); or just show that number. Eg: 23/45; Now, if you build a calculator or other such code how will you overcome this? I tried this simple code: https://code.sololearn.com/cl5YfK0mS8RH/ any idea?

17th Aug 2017, 7:27 AM
Rifat
Rifat - avatar
11 Respostas
+ 2
It has no problem showing the number it has problem with doing Arithmetic operations with such number. Eg: I tried double i = (10)/(23/45); or i = 10 / 0.10; And as always it gave an Exception in thread "main" java.lang.ArithmeticException: / by zero ; I can't assure about other languages yet.
17th Aug 2017, 7:38 AM
Rifat
Rifat - avatar
+ 2
I see even after casting into double the big operation is not resulting in right answers. Got example in that code.
17th Aug 2017, 8:45 AM
Rifat
Rifat - avatar
+ 1
I got the solution. The problem was especially for fractional numbers after 0. Solution: Up cast or down cast. on code playground, use try catch. on netbeans it worked all the time even without try catch block.
17th Aug 2017, 7:57 AM
Rifat
Rifat - avatar
0
after arithmetic calculations, how to show exact number, if you get the result such as 0.9
17th Aug 2017, 7:09 AM
Rifat
Rifat - avatar
0
reply : nop. If you look at the code, it shows double numbers in this formate : 0.0; that means not only int.
17th Aug 2017, 7:20 AM
Rifat
Rifat - avatar
0
Also I tried Bing: showing correct answers. Try this: ((3 / 9) * (8 / 10)) / (23 / 45) == 12 / 23 and you get this: ((3 / 9) * (8 / 10)) / (23 / 45) == 12 / 23 = True How other things and calculators are calculating these?
17th Aug 2017, 7:22 AM
Rifat
Rifat - avatar
0
so basically if the ans is between 1 and 0 it shows as 0.0 right????
17th Aug 2017, 7:25 AM
sayan chandra
sayan chandra - avatar
17th Aug 2017, 7:32 AM
sayan chandra
sayan chandra - avatar
- 1
rifat explain in details once more.. ehat exactly u want to do
17th Aug 2017, 6:58 AM
sayan chandra
sayan chandra - avatar
- 1
i dont do java but is there no thing to convert int from float.. looks like it prints the answer in int and so its always zero...
17th Aug 2017, 7:15 AM
sayan chandra
sayan chandra - avatar
- 1
compiler varies then
17th Aug 2017, 7:58 AM
sayan chandra
sayan chandra - avatar