Solved

Rounding

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
delphi parse string to params 3 136
How to debug For loops? 3 56
Moving (cutting/pasting) controls in a TTabbedNotebook... 7 43
DBCtrlGrid, Delphi, Scroll 7 26
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…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

856 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