title: Most significant decimal digit (or 0.3 - 0.1 = 0.1 )
body: <p>This operation should return <code>2</code>, but it returns <code>1</code> instead because of the floating point representation:</p>
  
  <pre><code>a &lt;- .3
  b &lt;- .1
  floor((a-b)*10)
  </code></pre>
  
  <p>I basically want the first digit after the point, of the actual base-10 result, not the floating-point computer's result. In this case <code>a</code> and <code>b</code> only have one decimal digit, but in most situations there will be more. Examples:</p>
  
  <ul>
  <li><code>0.3-0.1=0.2</code> so I want the <code>2</code></li>
  <li><code>0.5-0.001=0.499</code> so I want the <code>4</code></li>
  <li><code>0.925-0.113=0.812</code> so I want the <code>8</code></li>
  <li><code>0.57-0.11=0.46</code> so I want the <code>4</code></li>
  <li><code>0.12-0.11=0.01</code> so I want the <code>0</code></li>
  </ul>
  
  <p>that is, not rounding but truncating. I thought of using this:</p>
  
  <pre><code>floor(floor((a-b)*100)/10)
  </code></pre>
  
  <p>but I'm not sure if that is the best I can do.</p>
  
  <p><strong>update:</strong> indeed, it doesn't work (see comments below):</p>
  
  <pre><code>floor(floor((.9-.8)*100)/10) # gives 0 instead of 1
  floor(round((.5-.001)*100)/10) # gives 5 instead of 1
  </code></pre>
  
  <p><strong>update 2:</strong> think this does work (at least in all cases listed so far):</p>
  
  <pre><code>substring(as.character(a-b),first=3,last=3)
  </code></pre>
  
  <p>Suggestions?</p>