Formatting a number as hexadecimal using MessageFormat in Java
Asked Answered
H

0

6

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?

Hyehyena answered 4/7, 2018 at 15:31 Comment(6)
I would use Integer.toHexString() and format the string. You could have a more powerful MessageFormatter by writing your own.Jinx
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.Nordgren
This might do what you want. It's a pluggable ExtendedMessageFormat (extends MessageFormat) commons.apache.org/proper/commons-lang/apidocs/org/apache/…Jinx
MessageFormat does not support it in the pattern level.Onceover
An example using ExtendedMessageFormat alvinalexander.com/java/jwarehouse/commons-lang/src/test/java/…Jinx
@NikhilJain This is not a duplicate. This question is specifically about MessageFormat.Onceover

© 2022 - 2024 — McMap. All rights reserved.