I have problem in calculation in android, i am doing the calculation
((1 * (1 + ((0.025 * 12) * ((6-1) / 12))) / 6);
In php generate value
echo ((1*(1+((0.025*12)*((6-1)/12))))/6);
Result :
0.1875
But in android :
System.out.println(((1*(1+((0.025*12)*((6-1)/12))))/6));
Result :
0.16666666666666666
I've tried everything to do rounding on decimal values, but the results are different. How do i do the exact calculation to be able to adjust to the given value of php?
Thank you in advance.
You need to cast the return value of all decimal numbers to double or float, to get all the decimals. It'll default to integers, which mean you loose some data.
double d = (((1 * (1 + ((0.025 * 12) * ((double)(6 - 1) / 12)))) / 6));
Gives 1.875
double f = (((1 * (1 + ((0.025 * 12) * ((6 - 1) / 12)))) / 6));
Gives 1.666666666
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With