繁体   English   中英

不兼容的类型:可能从双精度转换为整数

[英]Incompatiple types: possible lossy conversion from double to int

我需要将总销售额除以500,以获得我正在处理的任务的折扣阈值,但我无法弄清楚出了什么问题。 抱歉,这是一个愚蠢的问题,但是我刚开始学习Java的前几周。

String nameDFF;
    String inputStringDFF;
    int quantityDFF, discountThresholdDFF;
    double salesPriceDFF, totalSalesAmountDFF;



    //Create a new Scanner object to read user's input
    Scanner keyboard = new Scanner(System.in);

    //Get the user's name 
    System.out.print("What is your name? ");
    nameDFF = keyboard.nextLine();

    //Get the the user's quantity they want to buy
    System.out.print("\nWhat is the quantity you want to buy?\n Enter a whole number greater than or equal to 1.");
    quantityDFF = keyboard.nextInt();

    //Get the sales price of the item
    System.out.print("\nWhat is the sales price of the item?\n Enter the value greater than 0.");
    salesPriceDFF = keyboard.nextDouble();

    //Calculate total sales amount
    totalSalesAmountDFF = quantityDFF * salesPriceDFF;

    //Calculate the discount threshold
    discountThresholdDFF = totalSalesAmountDFF / 500;
}

您将双精度浮点除以500,并将结果存储在整数中。

您实际上希望它与剩余的小数位数有什么关系? 是Math.floor还是只将非小数部分,Math.round取到最接近的整数,还是您实际上希望结果变量也具有双精度?

Java需要您的指导,因为您要Java在没有足够信息的情况下进行操作,因此会出现错误。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM