Dan
Dan

Reputation: 11069

Java DecimalFormat get Pattern as text

I have a case where I would like to create a DecimalFormat by setting various options directly. For example,

pattern.setNegativePrefix(myPrefix);
pattern.setNegativeSuffif(mySuffix);
pattern.setMinimumFractionDigits(2);

etc. But when all's said and done, I'd like to actually capture the pattern string that represents that so I can reuse it again. Can I do that using this method or do I have to construct the pattern string myself and pass it in?

In other words, I'm asking, is there an equivalent to the (non-existent) getPattern method in DecimalFormat?

Upvotes: 1

Views: 742

Answers (1)

rgettman
rgettman

Reputation: 178263

You're looking for the toPattern() method.

Synthesizes a pattern string that represents the current state of this Format object.

String text = pattern.toPattern();

Upvotes: 3

Related Questions