Hi,
What is the best way to format a number in Java?
How to format number in Java?
Thanks
Hi,
To format number in Java you can use the class java.text.NumberFormat.
Here is simple examples:
NumberFormat numberFormat = NumberFormat.getInstance(); // setting number after decimal places numberFormat.setMinimumFractionDigits(3); numberFormat.setMaximumFractionDigits(3); // from integer to String String formatNumber = numberFormat.format(1234);
Check full source code at NumberFormat In Java.
Thanks
Ads