How to format number in Java?

Ads

 
 

Share on Google+Share on Google+

Java Coder
How to format number in Java?
1 Answer(s)      6 months and 3 days ago
Posted in : Java Beginners

Hi,

What is the best way to format a number in Java?

How to format number in Java?

Thanks

Ads
View Answers

April 16, 2017 at 10:58 PM


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









Ads

 
Advertisement null

Ads