title: How to get Delphi Currency Type to Round like Excel all the time?
body: <p>I'm trying to get Delphi to Round like Excel but I can't. Here is the code:</p>
  
  <pre><code>procedure TForm1.Button1Click(Sender: TObject);
  var
   s : string;
   c : currency;
  begin
   c := 54321.245;
   s := '';
   s := s + Format('Variable: %m',[c]);
   s := s + chr(13);
   s := s + Format('   Literal: %m',[54321.245]);
   ShowMessage(s);
  end;
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/v0Mch.jpg" alt="Delphi Rounding"></p>
  
  <p>I'm using a currency variable that is set to 54321.245 and when I format this variable it rounds using Bankers Rounding. However, when I format the same value as a literal it rounds the way that Excel rounds. </p>
  
  <p>I was expecting this to round to <strong>$54,321.25</strong> whether it's formating a currency variable or a literal value. How can I make sure that Delphi rounds the same way as Excel every time?</p>
  
  <p><strong>Edit</strong></p>
  
  <pre><code>The rounding I expect to see is as follows:  
  54,321.245   = 54,321.25  
  54,321.2449  = 54,321.24  
  54,431.2499  = 54,421.25 
  </code></pre>
  
  <p>I am only using literals to show the different ways Delphi rounds. I expect to use variables in the actual code. </p>
  
  <p><strong><em>Note:</em></strong><br>
  If I change the variable from <strong>currency</strong> to <strong>extended</strong> it rounds correctly</p>
  
  <p><strong>Edit #2</strong>  </p>
  
  <p>Some have suggested that I do not have a clear understanding of my requirements, this is absolutely not true. I have a very clear understanding of my requirements, I'm obviously not doing a very good job of explaining them. The rounding method I want is two decimal places. When the deimal part has a thousandths value >= 0.005 I want it rounded to 0.01 the currency type offered by Delphi does not do this. I also tried this example using Microsoft SQL with a money datatype (which I assumed was the same as Delphi's currency) and SQL rounds it's money type the way I described.  </p>
  
  <ul>
  <li>SQL Money >= 0.005 = 0.01</li>
  <li>Delphi Currency >= 0.005 := 0.00</li>
  </ul>
  
  <p><strong>Edit #3</strong><br>
  Good Article: <a href="http://rvelthuis.de/articles/articles-floats.html" rel="noreferrer">http://rvelthuis.de/articles/articles-floats.html</a><br>
  Possible Solution: <a href="http://rvelthuis.de/programs/decimals.html" rel="noreferrer">http://rvelthuis.de/programs/decimals.html</a></p>
  
  <p><strong>Edit #4</strong><br>
  Here is one of the solutions from the Embarcadero discussion  </p>
  
  <pre><code>function RoundCurrency(const Value: Currency): Currency;
  var
    V64: Int64 absolute Result;
    Decimals: Integer;
  begin
    Result := Value;
    Decimals := V64 mod 100;
    Dec(V64, Decimals);
    case Decimals of
      -99 .. -50 : Dec(V64, 100);
      50 .. 99 : Inc(V64, 100);
    end;
  end;</code></pre>