求编一个JAVA程序

来源:百度知道 编辑:UC知道 时间:2024/06/17 04:28:55
我想把一个十进制数转换成二进制数 但要包括小数 哪位高手帮编一下 或帮我找个源程序,小第万分感谢!!

电脑没发运行 我感觉这次逻辑没错了 你试试再?

public class Go {

/**
* @param args
*/
public static void main(String[] args) {

int n=75;//n为十进制小数点后数字
int xiaoshu=0;
int length=String.valueOf(n).length();//length为小数点后位数
int x=1;
for(int i=length,yu=1;yu!=0;length++)
{
x=(x*(int)(Math.pow(10,length)))/2;
System.out.print(x);
yu=n%x;
xiaoshu =xiaoshu*10+n/x;
}
System.out.print(xiaoshu);
//xiaoshu为二进制小数小数点后数字
}

}

public class jbx {
public jbx() {
}
public static void main(String[] arges){
int i=123456;
String str2=Integer.toBinaryString(i);//二进制
String str8=Integer.toHexString(i);//八进制
String str16=Integer.toOctalString(i);//十六进制
System.out.println("二进制"+str2);
System.out.println("八进制"+str8);
System