简体   繁体   中英

How to display a double value in a JLabel

I have a Jlabel called Basic Salary and a JtextField called NoOfWorkingDays I need to calculate Net Salary for the no of Days a employee worked, So my code is like this,

float Sal=Float.parseFloat(lblSalary.getText());
float days=Float.parseFloat(txtNoofworking.getText());
float tot;
tot = (float) ((Sal/30.0)*days);
lblNetSal.setText(tot);

this code not giving the answer So Show me the mistake I have done here or Please show me the correct way of doing this

Convert float tot to String

tot = (float) ((Sal/30.0)*days);
String s = Float.toString(tot);
lblNetSal.setText(s);

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