java - GUI calculation issue -
i have been trying ever trying figure out why code jframe wont show correct calculations! when add numbers in windows calculator correct when use program different , incorrect. in program answer 520420 instead of 52420,5 in windows calculator. please tell me going wrong program , correct answer windows calculator? bellow calculate button adds numbers total price if check box selected!
private void calculatorbactionperformed(java.awt.event.actionevent evt) { double price = 0; if(shoestk.isselected()) { price = price + 120; } if(cricketbatck.isselected()) { price = price + 300; } if(bikeck.isselected()) { price = price + 20000; } if(watchck.isselected()) { price = price + 500000; } if(plasticbagck.isselected()) { price = price + 0.50; } system.out.println(price); string total = double.tostring(price); totaltxt.settext(total); } output of program total being incorrect. 
output of windows calcultor , result want.
if(bikeck.isselected()) { price = price + 20000; } if(watchck.isselected()) { price = price + 500000; } you've got trailing 0 in both of these cases. should 2000 , 50000 respectively.
also, in text 520420 screen shot shows 520420.5 looks plastic bag handled correctly.

Comments
Post a Comment