0

I am doing a exercise of a banking account with a txt file, my acount have name(String), acc number(String), balance(double). I need to convert the balance (column[2]) in to a double.

public static ArrayList<Account> readAccounts(Scanner input){
    String row;
    String[] column;
    ArrayList<Account> accounts = new ArrayList<>();
    while(input.hasNext()){
        row = input.nextLine();
        column = row.split(";");
        Account account = new Account(column[0], column[1], column[2]);
        account.toString();
        accounts.add(account);
    }
    return accounts;
}
Rgt
  • 1
  • 1
  • 2
    *I need to convert the balance (column[2]) in to a String.* I have **tremendous** news; `column[2]` **is** a `String`. Or I'm missing something very relevant here. – Elliott Frisch Dec 05 '21 at 12:22
  • You are right, what i need is the opposite, i will fix the post, thank you! – Rgt Dec 05 '21 at 12:24
  • *what i need is the opposite* `Double.parseDouble(column[2])` – Elliott Frisch Dec 05 '21 at 12:25
  • 1
    Another FYI Just because something is numeric and has a decimal point doesn't mean it has to be a floating point number. There is a fixed decimal called BigDecimal that is easier to deal with. – Nathan Hughes Dec 05 '21 at 12:26
  • Thank you both! I will close the question – Rgt Dec 05 '21 at 12:28
  • @NathanHughes There is also [`Currency`](https://docs.oracle.com/javase/8/docs/api/java/util/Currency.html). If you want to model money specifically. – Elliott Frisch Dec 05 '21 at 12:28

0 Answers0