Sloth Armstrong
Sloth Armstrong

Reputation: 1066

Is formatting negative percentages with java DecimalFormat possible?

I am trying to format percentages using the Java DecimalFormat() function. The format String I am using is

'#.##%;-#%'.

This is not giving me the negative results I would expect, e.g. -12% is showing as simply -12. Where am I going wrong?

Upvotes: 1

Views: 346

Answers (1)

Samuel
Samuel

Reputation: 2156

You can't use the percent sign in your pattern because it has a special meaning:

Multiply by 100 and show as percentage

See: javadoc, Special Pattern Characters

Upvotes: 2

Related Questions