How to format number in Java?

Ads
 

How to format number in Java?

Hi,

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

How to format number in Java?

Thanks

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









Related Tutorials/Questions & Answers:
How to format number in Java?
How to format number in Java?
Advertisements
Formatting a Number Using a Custom Format
Java2
php format number to 2 decimal places
Javah
Mysql Phone Number Format
how to generate bank account number?
Formatting and Parsing a Number for a Locale
Java Number Format
How to print this Format exactly?
Formatting a Number in Exponential Notation
Formatting a Message Containing a Number
how to print pdf format
How create csv format in jsf ?
ModuleNotFoundError: No module named 'javax'
ModuleNotFoundError: No module named 'javax'
How to convert EBCDIC format value into ASCII format value in java
How to format json String in Java
How to format json String in Java
Javap Tool application
how to get number of shards in elasticsearch
Javah -  Header File Generator
Artifacts of javax
how to validate national ID number
how to use stringtokenizer on table? and display in table format.
How to round a number to n decimal places in Java
how to create month wise serial number in java?
how to auto generate number in jsp with the database connection mysql for employee number?
how to auto generate number in jsp with the database connection mysql for employee number?
How to calculate sum of HH:MM:SS Format?

Ads