title: Using Perl to split a float
body: <p>Why did I lose precision using split? 
  My goal is to get just the fractional part, all of it.</p>
  
  <pre><code>$a = 123456789.123456789;
  @b = split(/\./, $a);
  $baseDec = "." . $b[1];
  </code></pre>
  
  <p>Above gives $baseDec == .123457</p>
  
  <p>But this gives the correct precision:
  Is it the right way to do it?  <strong>CORRECTION: THIS GIVES THIS SAME BAD PRECISION!
    I did not properly test the code. Sorry!</strong></p>
  
  <pre><code>$a = 123456789.123456789;
  @b = split(/\./, $a);
  $baseInt = $b[0];
  $baseDec = $a - $baseInt;
  </code></pre>
  
  <p>Should I be using Math::BigFloat?</p>
  
  <p><strong>Edit:</strong> $a should be a string <code>$a = "123456789.123456789";</code> and then the original code works. Until I figure out how to get my Perl to work with longdouble, I can't test the original question. The answer seems to be that I lost precision because $a is being stored in a double (52 bits ~ 15 decimal digits, as @Ben stated below). <code>print $a</code> gives <code>123456789.123457</code>.</p>