I’m trying to set a Data format in POI so that it will show values like this:
12.5%
12.75% 15%
So, it should only show the decimal point if needed and then only show the fractional values if needed.
I have it partially working using this format:
stylePercentage.setDataFormat(workbook.createDataFormat().getFormat("#.##%"));
However, this prints 15% like:
15.%
From the research I’ve been doing, I’m not sure if what I am trying is possible.
Is there a way to alter the data formatter to only show the decimal point if it is needed?
Check out BuiltinFormats.
HSSFDataFormat has a method that can retrieve these for you.
workbook.createDataFormat().getFormat(HSSFDataFormat.getBuiltinFormat("0.00%"));
Tags: javajava