Solved

Rounding

Posted on 2003-11-26
4
2,275 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 100 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 100 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

Get HTML5 Certified

Want to be a web developer? You'll need to know HTML. Prepare for HTML5 certification by enrolling in July's Course of the Month! It's free for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses
Course of the Month10 days, 7 hours left to enroll

628 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