Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
206 views
Welcome To Ask or Share your Answers For Others

1 Answer

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...