Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Show Normal Number Instead of Exponential Form

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

like image 636
Shahzad Avatar asked Sep 03 '25 05:09

Shahzad


1 Answers

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
like image 180
Irshad A Khan Avatar answered Sep 04 '25 18:09

Irshad A Khan