I want to show number in a Normal form instead of Exponential Form
For Example My Number is stored in a double variable with value 1234567890123
I want to get the exact representation. but when I pass it to some TextView for display, it becomes 1.234E12
Try Out with the Big decimal class in java..
Big decimal class has the advantage of some inbuilt Rounding function which you can use for example:
Double a = 7.77d * 100000000; //Multiply Operation
System.out.println("Large multiply " + a.doubleValue());
System.out.println("Magic of big decimal " + BigDecimal.valueOf(a).setScale(0,RoundingMode.HALF_EVEN).toPlainString());
a = 7.77d / 100000; //Devide Operation
System.out.println("Devide operation " + a.doubleValue());
System.out.println("Magic of big decimal " + BigDecimal.valueOf(a).toPlainString());
DecimalFormat formatter = new DecimalFormat("0.000000");
System.out.println("Trimming the big string : "+formatter .format(a));
Output :
Large multiply 7.77E8
Magic of big decimal 777000000
Devide operation 7.769999999999999E-5
Magic of big decimal 0.00007769999999999999
Trimming the big string : 0.000078
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With