Solved

Rounding

Posted on 2003-11-26
4
2,239 Views
Last Modified: 2008-03-10
Hi!

Here is an easy one.

I started a new Delphi project and put 2 buttons on the empty form.

On the OnClick event of Button1, I inserted this line of code:
showmessage(FormatCurr('0.00',2.955) + #13 + FloatToStr(RoundTo(2.955,-2)));

On the OnClick event of Button2, I inserted this line of code:
showmessage(FormatCurr('0.00',3.955) + #13 + FloatToStr(RoundTo(3.955,-2)));

The only difference between the two lines is the constant float number.  2.955 for button1 and 3.955 for button2.

I ran the app and clicked on the buttons.

Button1 gave me this:
2.96
2.96

Button2 gave me this:
3.96
3.95

Why can't it be the same ?

What I need is to round 3.955 to 3.95 and 1.755 to 1.75 (while still rounding 3.956 to 3.96 and 1.755 to 1.76).  How do I do that ?

Thanks!!
0
Comment
Question by:qas
  • 2
4 Comments
 

Assisted Solution

by:JGMS
JGMS earned 100 total points
Comment Utility
I tried it in D7 and it worked normal.
You may check out the setting of the function SetRoundMode (rmTruncate will likely do what you see. Better use rmUp)

Regards JGMS      
0
 

Author Comment

by:qas
Comment Utility
Well I'm all messed up....

What I need, in fact, is that this function: FormatCurr('0.00',3.955) gives me 3.95.  For now, it returns me 3.96.

I'll check with the SetRoundMode and get back to you.  Thanks JGMS for the fast comment.
0
 
LVL 17

Accepted Solution

by:
geobul earned 100 total points
Comment Utility
Hi,

Try FormatCurr('0.00',RoundTo(3.955,-2)) instead.

Regards, Geo
0
 

Author Comment

by:qas
Comment Utility
My fault!

This was a stupid question from me....

My app is working fine.

Thanks anyways for the fast solutions.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now