How to compute Discount using Java? (Code please) Thankss! | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
0

How to compute Discount using Java? (Code please) Thankss!

7th Sep 2018, 8:02 AM
MyElMaMi
2 Respostas
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?
7th Sep 2018, 8:17 AM
Daniele Bonomi
Daniele Bonomi - avatar
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); }
7th Sep 2018, 1:00 PM
Mohammed