'Calculate correct Price($) according to current Gas Price
In my Android app(Android studio java), I have to calculate gas volume in SCM(correct to the first decimal place only) to be provided from the amount user want the gas for but the issue I am having is for a few different amount the gas volume calculated comes to be same for e.g.
If the gas price per SCM is 28.6
The user wants the gas for the amount of 10
the calculated gas volume to be provided is 0.3 SCM
But the gas volume for the amounts 9 and 8 is also 0.3 SCM
I want the price to be set automatically to 8 i.e. the minimum price for the same volume of gas which is provided for price 10 instead of 10 so that the user gets the same volume of gas and does not overpay.
main_recharge_amt =4; // Gas needed for this Amount
gas_rate = 28.6; // Gas per unit price
DecimalFormat df = new DecimalFormat("#.#");
Double gas_total =main_recharge_amt/ Double.parseDouble(gas_rate);
String gt =df.format(gas_total);
gas_total =Double.parseDouble(gt);
gas_total comes 0.1 but if main_recharge_amt = 2 then also this comes as 0.1
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|