How do I change a string to a double type?

Asked 2 years ago, Updated 2 years ago, 87 views

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));
}

I have to calculate the total in another class, but can't I change the string back to double?

string java double

2022-09-21 21:36

1 Answers

If you use Double.parseDouble(), change the String to double.

String text = "12.34"; 
double value = Double.parseDouble(text);
double total = Double.parseDouble(jlbTotal.getText());
double price = Double.parseDouble(jlbPrice.getText());

I think you can do it like this.


2022-09-21 21:36

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.