I want to write 5 digit zip code to an Excel file. for ex. for number 01803 if I don't convert it to string it will store it as 01803 string but shows an error on excel file.So I want to store it as Big Decimal number without stripping the leading 0's.but Big decimal by default strips it for the current case.
In excel, when I store it as string and convert that to number in excel it will strip the leading zero's
Address address = new Address();
address.setPostalCode("01803");
String postCode = address.getPostalCode();
if(postCode.matches("^[0-9]*$") && postCode.length() > 2){
if(postCode.charAt(0) == '0'){
System.out.println(postCode.toString());
} else {
System.out.println(new BigDecimal(postCode).doubleValue());
}
}else {
System.out.println(address.getPostalCode());
}