Convertir un numero Double a Cadena (Notación decimal Real) No Notación Científica
Convierte:
1.0E-6
a una cadena
0.0000010
Convierte:
1.0E-6
a una cadena
0.0000010
public String doubleToString(double num){
String str="",aux="",aux2="";
aux=""+num;
int exp=0;
int p;
boolean positivo=true;
if(num<0){
positivo=false;
}
System.out.println(num);
if(aux.contains("E-")){
exp=Integer.parseInt(aux.substring(aux.lastIndexOf("E")+1));
exp=exp*(-1);
str=""+aux.substring(0,aux.lastIndexOf("E"));
str=str.replace("-","");
while(exp>0){
str="0"+str;
exp--;
}
str=str.replace(".","");
str=str.substring(0,1)+"."+str.substring(1);
if(positivo==false){
str="-"+str;
}
}else if(aux.contains("E")){
exp=Integer.parseInt(aux.substring(aux.lastIndexOf("E")+1));
int e=exp;
str=""+aux.substring(0,aux.lastIndexOf("E"));
if(str.contains(".")){
int e2=str.length()-str.indexOf(".")-1;
e=e-e2;
int pt=str.indexOf(".")+exp;
str=str.replace(".","");
while(e>0){
str=str+"0";
e--;
}
if(pt<str.length()){
str=str.substring(0,pt)+"."+str.substring(pt);
}
}
}else{
return aux;
}
return str;
}
No hay comentarios.:
Publicar un comentario
Cualquier Duda Envíame un email