0
please help me out i want discount rate upto decimal figure (upto 6 digit)
public class DiscountPrice{ public static void main(String[] args) { int offer; int disc; double rate; System.out.println("Enter the current offer price:-"); Scanner offerPrice = new Scanner (System.in); offer = offerPrice.nextInt(); System.out.println("Enter the discount price "); Scanner discPrice = new Scanner (System.in); disc = discPrice.nextInt(); rate = 100 - (disc * 100 / offer); System.out.println("the discount percentage is " + (rate)); } } //the discount percentage rate is not coming in exact decimal figures
2 Antworten
0
in rate calculation, offer, disc both and 100 all integers so result also you get only Integer. No decimal point value.
To result a double value, use atleast one double in calculation like 100.0
Or
take one of offer, disc as double values..
Why are taking two Scanner objects..? One is enough for a program.. You can use only one..
0
thanks..... it works.... :)