0
How to compute Discount using Java? (Code please) Thankss!
2 Respuestas
0
Exactly as in normal maths:
20% discount on €500
public float discount(float cost, float discount)
{ //500:x=100:20
return cost*discount/100;
}
Why do you put javascript in your tag?
0
In mathematics, a percentage is a number or ratio expressed as a fraction of 100. So it must be represented by floating point data type double not float, because here the accuracy is very important.
The basic way to calculate a discount is to multiply the original price by the decimal form of the percentage.
price *= (1 - discount_percentage)
double updatePrice(double price, double discount) {
return price*(1-discount);
}