title: Fixing Floating Point Error
body: <p>I have some code that gets the leading value (non-zero) of a Double using normal math instead of String Math...</p>
  
  <p>For Example:<br>
  0.020 would return 2<br>
  3.12 would return 3<br>
  1000 <b>should</b> return 1</p>
  
  <p>The code I have at the moment is:</p>
  
  <pre><code>LeadingValue := Trunc(ResultValue * Power(10, -(Floor(Log10(ResultValue)))))
  </code></pre>
  
  <p>However when ResultValue is 1000 then LeadingValue ends up as 0.</p>
  
  <p>What can I do to fix this problem I'm assuming is being caused by floating point errors?</p>
  
  <p>Thanks.</p>