Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to configure MessageFormat for numbers globaly

I would like to change the way MessageFormat prints out numbers.

Integer foo = 99888;
String bar = MessageFormat.format("{0}", foo);

Observed value is "99,888".

Desired value is "99888".

What I could do is this:

String bar = MessageFormat.format("{0, number,#}", foo);

The problem is that I have to change it in a project with more than 10'000 MessageFormat.format(). So this is not really the way I would like to do it.

Do you know if there is a way to change the format of numbers given to MessageFormat.format() globally?

like image 210
marcramser Avatar asked Oct 16 '25 09:10

marcramser


1 Answers

Other than writing a very strange aspect I don't believe there is a way. That's the price you pay for using a static method that you can't modify.

I'd look into doing a bulk change either using your favourite IDE or command line tools e.g. sed. If you want to change all occurrences of {0} into {0,number,#} it should be enough to

sed -i -e 's/{0}/{0,number,#}/g' MyClass.java
like image 145
Karol Dowbecki Avatar answered Oct 17 '25 21:10

Karol Dowbecki



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!