-1

I need users to be able to input numbers in the BigDecimal data type.

Numbers[i] = (BigDecimal)JOptionPane.showInputDialog(frame,"Type in a Number",0);

This is the code I tried to use but I get an error saying "Cannot cast from String to BigDecimal."

Any Advice?

2 Answers2

2

You should read docs first. https://docs.oracle.com/javase/7/docs/api/java/math/BigDecimal.html

BigDecimal has a constructor which takes a string as a representation of your decimal.

Number num = new BigDecimal(JOptionPane.showInputDialog(frame,"Type in a Number",0));
David
  • 5,203
  • 2
  • 16
  • 17
1

You need to use the constructor:

Numbers[i] = new BigDecimal(
   JOptionPane.showInputDialog(frame,"Type in a Number",0));
Laurel
  • 5,965
  • 14
  • 31
  • 57