I am trying to write a program that stores money in a variable, so I am using Bigdecimal type as it was advised by other memebers here.. But what I am trying to do is this.. user can type in what ever way he wants means to say, he can type
24
or
24.0
or
24.00
so as you can see that I am giving the user flexibility to type at his own convenience. But in the end the variable will be stored in an array (BigDecimal array) so when it stores I want to store with and only 2decimal places. Why I say that is if the user types in 24 I want to store 24.00 NOT 24 or 24.0 JUST 24.00 or if he enters 24.00 then that will be stored with out any modification done to it.. how to do this.. Sample code provided below.
BigDecimal bala;
BigDecimal balintake;
static BigDecimal[] bal= new BigDecimal[20];
Scanner sc = new Scanner(System.in);
balintake = sc.nextBigDecimal();
bala.setScale(2,RoundingMode.HALF_UP);
bal[0] = bala;
But this is not working as according to my requirements.