Friday, 27 October 2017

How to convert exponential form of double number to decimal form



To Convert Exponential form of number to non exponential form in
java.text.we have two class
 java.text.DecimalFormat;
 java.text.NumberFormat;

we use them like

NumberFormat  numberFormat = new DecimalFormat("#0.00");

we pass #0.00 pattern in DecimalFormat class constructor as argument.

here are the code for converting number .

package in.jk;
import java.text.DecimalFormat;
import java.text.NumberFormat;

public class Test {

public static void main(String[] args) {
System.out.println();
double doubleValue = 200E7;

NumberFormat formatter = new DecimalFormat("#0.00");
System.out.println("Number is exponential  format "+doubleValue);
System.out.println();
String claimAmt = formatter.format(doubleValue);
System.out.println("Number is Decimal format "+claimAmt);

}

}


Out on Console look like this .......

Number in exponential  format 2.0E9

Number in Decimal format 2000000000.00







No comments:

Post a Comment