Sajid Anam
Sajid Anam

Reputation: 139

Converting Exponential value to Decimal Android

I have a String in the format of "6.151536E-8"

How can i convert it to a string or int as 0.000000061 ?

Upvotes: 0

Views: 1154

Answers (1)

ednincer
ednincer

Reputation: 951

Use this if you want to have just 2 significant digits:

String str = "6.151536E-8";  
BigDecimal bd = new BigDecimal(str);
bd = bd.round(new MathContext(2, RoundingMode.HALF_UP));
System.out.println(bd.toPlainString());

This prints: 0.000000062

If you want to round down to 0.000000061 then use RoundingMode.DOWN

Upvotes: 5

Related Questions