将字符串转换为Java中的两倍

问题:

我想将double值更改为String

if((e.getSource() == jBook)) {
    String name = jlbName.getText();
    String date = jlbDateProduce.getText();
    String time = jr1.getText();
    int number = (Integer.parseInt(jtfNoOfTicket.getText().trim()));
    String total = jlbTotal.getText();
    String price = jlbPrice.getText();

    //Passing
    ticketReservation frame = new ticketReservation(
        name, date, time, price, total, String.valueOf(number));
}

在另一个类中,我需要使用该值来计算。有没有办法将String转换为double

回答:

您可以使用Double.parseDouble()String转换为double

String text = "12.34"; // example String
double value = Double.parseDouble(text);

对于你的情况,它看起来像你想要的:

double total = Double.parseDouble(jlbTotal.getText());
double price = Double.parseDouble(jlbPrice.getText());

 
 
Code问答: http://codewenda.com/topics/python/
Stackoverflow: Convert String to double in Java

*转载请注明本文链接以及stackoverflow的英文链接

发表评论

电子邮件地址不会被公开。 必填项已用*标注

20 − = 12