One percent discount doesn't work. How do I round this issue down?

Geferson :

Good day, I make a method with a discount on the number but the one percent discount does not work . Problem with rounding numbers ?

Waiting: price 65.

Reality: price 66.

CODE:

public class Main {
    public static void main(String[] args) {
        int discount = 1;
        int price = 66;
        price -= (int) (discount * (price / 100));
        System.out.println(price);
    }
}

Please tell me how to round it down ?

SOLUTION:

public class Main {
    public static void main(String[] args) {
        int discount = 1;
        int price = 66;


        double amountOfDiscount = (discount * (price / 100.0f));
        double priceWithDiscountDoubleType = (price - amountOfDiscount);
        int priceWithDiscount = (int) 
        Math.floor(priceWithDiscountDoubleType);

        System.out.println(priceWithDiscount);

    }
}
Fred :

It is because you're using int to store the prices etc. Try using floating point numbers like float or double

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=292390&siteId=1