I have a string array in an object which is storing a decimal value.
String [] array = "12345.123456789";
I want it to be formatted as 12345.1234
I tried it with the following but resulted in a Number Format Exception.
BigDecimal value = new BigDecimal(array.toString()).setScale( 4, BigDecimal.ROUND_HALF_UP );
array = ( Object )value.toString();
I am new to java so can anyone please help…
String [] array = "12345.123456789";is not a valid statement – either it is a String or an array, so you need to choose between the following two statements:If you use the first form, you can round it with:
If you use the second form, you can use this: