第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Java netbeans - 如果 jtextfield 值為空,如何將 jtextfield

Java netbeans - 如果 jtextfield 值為空,如何將 jtextfield

繁華開滿天機 2021-09-03 10:13:44
double B=Double.parseDouble(emp_txt2.getText());    double C=Double.parseDouble(nopay_txt3.getText());    double E=Double.parseDouble(wop_txt4.getText());    double F=Double.parseDouble(wop_txt5.getText());   double f =B+C+E+F;   String p = String.format("%.2f",f);   lb1_total3.setText(p);當 jtextfield 為空時,我想將雙 B、C、E、F 值分配為零。
查看完整描述

2 回答

?
紅糖糍粑

TA貢獻1815條經驗 獲得超6個贊

您可以使用此方法代替Double.parseDouble。


public static double tryParsDouble(String s, double defaultValue) {

     if (s == null) return defaultValue;


     try {

         return Double.parseDouble(s);

     } catch (NumberFormatException x) {

         return defaultValue;

     }  

}

然后到:


double F = tryParsDouble(wop_txt5.getText(), 0.0);


查看完整回答
反對 回復 2021-09-03
?
慕斯王

TA貢獻1864條經驗 獲得超2個贊

嘗試在emp_text2文本字段中輸入值,代碼分別返回以下值: "", "  ", "1", "1.1", "-1.1","1.0  "返回0.0, 0.0, 1.0, 1.1, -1.1, 1.0。


如果輸入是 會發(fā)生什么"1.1x"?這會拋出NumberFormatException- 應用程序需要弄清楚要做什么。


double value = getDoubleValue(emp_text2.getText());

...


private static double getDoubleValue(String input) {


    double result = 0d;


    if ((input == null) || input.trim().isEmpty()) {

        return result;

    }


    try {

        result = Double.parseDouble(input);

    }

    catch (NumberFormatException ex) {

        // return result -or-

        // rethrow the exception -or-

        // whatever the application logic says

    }


    return result;

}


查看完整回答
反對 回復 2021-09-03
  • 2 回答
  • 0 關注
  • 195 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號