import java.util.Scanner;
public class Main {
static String convert(double x)
{
String string="";
for(int n=0;n<20;n++)
{
x*=2;
if(x==0)break;
if(x>=1)
{
string+="1";
x-=1;
}
else {
string+="0";
}
}
return string;
}
public static void main(String[] args) {
Scanner scanner=new Scanner(System.in);
while(scanner.hasNext())
{
double number=scanner.nextDouble();
int fore=(int)number;
double back=number-fore;
String string1=Integer.toBinaryString(fore);
String string2=convert(back);
System.out.print(string1);
if(string2.compareTo("")!=0)
{
if(string2.length()>20)
{
string2=string2.substring(0,19);
}
int i;
boolean flag=false;
for(i=string2.length()-1;i>=0;i--)
{
if(string2.charAt(i)!='0')
{
flag=true;break;
}
}
if(flag)
{
System.out.print(".");
string2=string2.substring(0,i+1);
System.out.print(string2);
}
}
System.out.println();
}
}
}
nyoj 647 奋斗小蜗牛在请客(浮点数转换二进制)
最新推荐文章于 2018-07-26 10:27:09 发布