Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Rounding

Posted on 2003-11-26
4
Medium Priority
?
2,279 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 

Assisted Solution

by:JGMS
JGMS earned 400 total points
ID: 9827393
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
ID: 9827535
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 400 total points
ID: 9831485
Hi,

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

Regards, Geo
0
 

Author Comment

by:qas
ID: 9831946
My fault!

This was a stupid question from me....

My app is working fine.

Thanks anyways for the fast solutions.
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

715 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