BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

RoundTo Problem with Delphi

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi VCL Components Using
View previous topic :: View next topic  
Author Message
Phlox
Guest





PostPosted: Wed Jul 30, 2003 11:16 am    Post subject: RoundTo Problem with Delphi Reply with quote



Hi,

is Delphi able to round in the following way:

1.235 -> 1.24
1.245 -> 1.25

The RoundTo function is retuning eiter way 1.24 !!!!

Thanks



Back to top
John Leavey
Guest





PostPosted: Wed Jul 30, 2003 12:43 pm    Post subject: Re: RoundTo Problem with Delphi Reply with quote



On Wed, 30 Jul 2003 13:16:31 +0200, "Phlox" <Master_Phlox (AT) web (DOT) de> wrote:

Quote:
Hi,

is Delphi able to round in the following way:

1.235 -> 1.24
1.245 -> 1.25

The RoundTo function is retuning eiter way 1.24 !!!!

RoundTo() calls Round() which uses "banker's rounding" - rounds towards nearest even
number.

For the rounding you want, replace RoundTo() with this :-


function MyRoundTo(const AValue: Double; const ADigit: TRoundToRange): Double;
var
LFactor: Double;
begin
LFactor := IntPower(10, ADigit);
Result := Trunc( ( AValue / LFactor ) + 0.5) * LFactor;
end;


John Leavey


Back to top
Yahia El-Qasem
Guest





PostPosted: Wed Jul 30, 2003 4:00 pm    Post subject: Re: RoundTo Problem with Delphi Reply with quote



Use SimpleRoundTo from the Delphi RTL - it uses the rounding algorithm you
want...

Yahia



Back to top
Achim Berg
Guest





PostPosted: Wed Jul 30, 2003 8:22 pm    Post subject: Re: RoundTo Problem with Delphi Reply with quote

Use SimpleRoundTo

Achim


"Phlox" <Master_Phlox (AT) web (DOT) de> schrieb im Newsbeitrag
news:3f27a970$2 (AT) newsgroups (DOT) borland.com...
Quote:
Hi,

is Delphi able to round in the following way:

1.235 -> 1.24
1.245 -> 1.25

The RoundTo function is retuning eiter way 1.24 !!!!

Thanks





Back to top
Martin Stoeckli
Guest





PostPosted: Thu Jul 31, 2003 7:37 am    Post subject: Re: RoundTo Problem with Delphi Reply with quote

Hello

SimpleRoundTo would be the function to use, but unfortunately it has
problems with negative numbers.

example:
-8.4 will be rounded to -7

The problem is already logged.

Best regards:
Martin



"Achim Berg" <Achim.Berg (AT) Corporate-Planning (DOT) com> schrieb im Newsbeitrag
news:3f2828f5$1 (AT) newsgroups (DOT) borland.com...
Quote:
Use SimpleRoundTo

Achim


"Phlox" <Master_Phlox (AT) web (DOT) de> schrieb im Newsbeitrag
news:3f27a970$2 (AT) newsgroups (DOT) borland.com...
Hi,

is Delphi able to round in the following way:

1.235 -> 1.24
1.245 -> 1.25

The RoundTo function is retuning eiter way 1.24 !!!!

Thanks




Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi VCL Components Using All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.