How do I use MessageFormat
to format a number in hexadecimal? I have an existing MessageFormat
pattern, and the customer wants to change it from a decimal number to a three-digit hex number. Is this possible using MessageFormat
? Or do I have to switch to a more powerful formatter? Or some other trick?
Asked
Active
Viewed 605 times
6

Ron Romero
- 9,211
- 8
- 43
- 64
-
1I would use Integer.toHexString() and format the string. You could have a more powerful MessageFormatter by writing your own. – Peter Lawrey Jul 04 '18 at 15:33
-
Instead of providing a number, provides an hexadecimal String of that number, and stick to MessageFormat. Possibly provide both options with different indexes for better flexibility. – kumesana Jul 04 '18 at 15:34
-
This might do what you want. It's a pluggable ExtendedMessageFormat (extends MessageFormat) https://commons.apache.org/proper/commons-lang/apidocs/org/apache/commons/lang3/text/ExtendedMessageFormat.html – Peter Lawrey Jul 04 '18 at 15:36
-
1`MessageFormat` does not support it in the pattern level. – lexicore Jul 04 '18 at 15:38
-
An example using ExtendedMessageFormat https://alvinalexander.com/java/jwarehouse/commons-lang/src/test/java/org/apache/commons/lang3/text/ExtendedMessageFormatTest.java.shtml – Peter Lawrey Jul 04 '18 at 15:39
-
@NikhilJain This is not a duplicate. This question is specifically about `MessageFormat`. – lexicore Jul 04 '18 at 16:55