You are right 
I use this piece of code when I want two 9 digits to rounded.
Changing a little bit the function, I think you get the wanted results
(Concole application in D7)
/*************************************/
program Project1;
{$APPTYPE CONSOLE}
uses
  SysUtils;

function DoubleStripDigits(a:Double;dig:integer):String;
var p: Integer;
begin
  result := floatToStr(a);
  p := pos(DecimalSeparator, result);
  if p>0 then
    result := copy(result, 1, p + dig);
end;
  var
   i  : integer;
   a : double;
   s : string;
begin
//  a := 7751.9 / 2991.546546;
  a := 2.599999999996;
  writeln('a->',a:10:20);
  for i := 9 downto 0 do
  begin
    s := DoubleStripDigits(a, i);
    writeln(i, '->', s);
  end;
  readln;
end.
*****************************/
you get
      2.59999999999600018000 <- forcing to write with too many digits look an 
error
9->2,599999999
8->2,59999999
7->2,5999999
6->2,599999
5->2,59999
4->2,5999
3->2,599
2->2,59
1->2,5
0->2,

*********** REPLY SEPARATOR  ***********

On 23/03/2007 at 11:41 Bobby Clarke wrote:

>Hi Antonis
>
>The code below will give different results from the others. Consider 
>starting with 2.5996. Your solution will round up to 2.6.  Other code 
>would  return 2.5. It really depends what result you actually want for 
>any input.
>
>Bobby Clarke
>
>
>
>Antonis Tsourinakis wrote:
>>
>> Also you can try this
>>
>> function DoubleStripDigits(a:Double;dig:integer):String;
>> begin
>> // because format rounds, add 2 more digits then wanted
>> result := format('%.*f',[dig+2, a]);
>> // and then cut them
>> result := copy(result,1,length(result)-2);
>> end;
>>
>> calling as
>> DoubleStripDigits(a,2)
>> to have as string
>> or
>> StrToFloatDef(DoubleStripDigits(a,2),0)
>> to have it as double
>>
>> *********** REPLY SEPARATOR ***********
>> >Arsen Khachatryan wrote:
>> >
>> > Hello world how are you.
>> > Im doing calculation in my delphi program for example im calculating
>> > 7751.9 / 2991 and geting result 2,57970578401872 how can I cut after
>> > 2.5 that its calculate like this 7751.9/2991 = 2.5 and not
>> > 2,57970578401872
>> >
>> **************************************
>>
>> 
>> ------------------------------------------------------------------------
>>
>> No virus found in this incoming message.
>> Checked by AVG Free Edition.
>> Version: 7.5.446 / Virus Database: 268.18.13/726 - Release Date:
>18/03/2007 15:34
>>   
>
>
>[Non-text portions of this message have been removed]
>
>
>
>-----------------------------------------------------
>Home page: http://groups.yahoo.com/group/delphi-en/
>To unsubscribe: [EMAIL PROTECTED] 
>Yahoo! Groups Links
>
>
>


Reply via email to