Solved

Rounding

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
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…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

734 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