mirror of
				https://gitee.com/coder-xiaomo/leetcode-problemset
				synced 2025-11-04 03:33:12 +08:00 
			
		
		
		
	
		
			
				
	
	
		
			24 lines
		
	
	
		
			800 B
		
	
	
	
		
			HTML
		
	
	
	
	
	
			
		
		
	
	
			24 lines
		
	
	
		
			800 B
		
	
	
	
		
			HTML
		
	
	
	
	
	
<p>Given a real number between 0 and 1 (e.g., 0.72) that is passed in as a double, print the binary representation. If the number cannot be represented accurately in binary with at most 32 characters, print "ERROR".</p>
 | 
						|
 | 
						|
 | 
						|
 | 
						|
<p><strong>Example1:</strong></p>
 | 
						|
 | 
						|
 | 
						|
 | 
						|
<pre>
 | 
						|
 | 
						|
<strong> Input</strong>: 0.625
 | 
						|
 | 
						|
<strong> Output</strong>: "0.101"
 | 
						|
 | 
						|
</pre>
 | 
						|
 | 
						|
 | 
						|
 | 
						|
<p><strong>Example2:</strong></p>
 | 
						|
 | 
						|
 | 
						|
 | 
						|
<pre>
 | 
						|
 | 
						|
<strong> Input</strong>: 0.1
 | 
						|
 | 
						|
<strong> Output</strong>: "ERROR"
 | 
						|
 | 
						|
<strong> Note</strong>: 0.1 cannot be represented accurately in binary.
 | 
						|
 | 
						|
</pre>
 | 
						|
 | 
						|
 | 
						|
 | 
						|
<p><strong>Note: </strong></p>
 | 
						|
 | 
						|
 | 
						|
 | 
						|
<ul>
 | 
						|
 | 
						|
	<li>This two charaters "0." should be counted into 32 characters.</li>
 | 
						|
 | 
						|
	<li>The number of decimal places for <code>num</code> is at most 6 digits</li>
 | 
						|
 | 
						|
</ul>
 | 
						|
 |