简体   繁体   中英

Getting output of 2 numbers after the decimal point

New to java, i am trying to get output of variables grossPayConv, taxesConv and netPayConv to have the output of XX.XX(having 2 places after the decimal). i believe i am casting wrong or something. i keep getting numbers with no values after the decimal. thanks, sorry for the basic question, can't seem to get it.

PS = if your curious about the variable names... Conv - meaning conversion

System.out.println("hours worked: ");
double hours = input2.nextDouble();

System.out.println("hourly pay rate: ");

double payHours = input3.nextDouble(); 
double grossPay = payHours*hours;
double grossPayConv = (int)(grossPay*100)/100;
double taxes = grossPay*TX;
double taxesConv = (int)(taxes * 100) / 100;
double netPay = grossPay-taxes;
double netPayConv = (int)(netPay*100)/100;

为什么将输出强制转换为int.Update,如下所示:

double grossPayConv = (grossPay*100)/100;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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