Created
November 5, 2014 01:43
-
-
Save jimbray/80b8b90ef21161ab83f1 to your computer and use it in GitHub Desktop.
将科学计数法转换为常规计数法
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 将科学计数法转换为常规计数法 | |
*/ | |
public static String ConScience2NumValue(String str) | |
{ | |
int len = Integer.parseInt(str.substring(getNum(str),getNum(str)+1)); | |
String bit = "1"; | |
for(int i = 0 ; i<len;i++) | |
{ | |
bit+="0"; | |
} | |
//BigDecimal bitResult = new BigDecimal(bit); | |
//BigDecimal result = bitResult.multiply(getDecimal(str)); | |
if(str.contains("E")) { | |
BigDecimal last = new BigDecimal(bit).multiply(getDecimal(str)).setScale(1,1); | |
return last.toString(); | |
} else { | |
return str ; | |
} | |
} | |
public static int getNum(String str) | |
{ | |
return str.indexOf('E')+1; | |
} | |
public static BigDecimal getDecimal(String str) | |
{ | |
return new BigDecimal(str.substring(0, str.indexOf('E'))); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment