?
Solved

Rounding to the nearest 0.05

Posted on 2003-02-24
6
Medium Priority
?
630 Views
Last Modified: 2010-04-04
This question should be easy, how do you round a variable up or down to the nearest 0.05

Thanks

Dan
0
Comment
Question by:danny1979
[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
6 Comments
 
LVL 3

Expert Comment

by:emadat
ID: 8010289
If you mean to the nearest second digit then:
Result := Round(your_number*10) / 10;
0
 
LVL 3

Expert Comment

by:sfock
ID: 8010772
not the smartest solution, but should work:

function roundDot05 (Value : real) : real;
  function getModifier(ModValue : real) : real;
  begin
    if ModValue < 0.25 then
      result := 0
    else if ModValue > 0.75 then
      Result := 1
    else
      Result := 0.5;
  end;
begin
  Result := (Int(Value * 10) + getModifier(value*10 - Int(Value * 10))) / 10
end;
0
 

Expert Comment

by:luisseixas
ID: 8011039
It's easy. Multiply it by 20, round it, and then, divide it by 20. The results are:

13,02 = 13,00
13,03 = 13,05

N -> Your real number
R -> Result

R := round(N*20)/20;
0
Industry Leaders: 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!

 
LVL 3

Expert Comment

by:ILE
ID: 8011826
this is a coplete solution

function round05(a:real):real;
begin
round05:=round(a*20)/20;
end;
0
 
LVL 3

Accepted Solution

by:
ILE earned 80 total points
ID: 8011853
this is a coplete solution

function round05(a:real):real;
begin
round05:=round(a*20)/20;
end;
0
 

Expert Comment

by:brownberry
ID: 26477129
This solution helped me.  I was trying to do similar rounding...to the nearest 1/4 lb, 1/2 lb, 1/0 lb for calculating weight for shipping charges.  Using the example, I was able to write my solution using Cobol.  It would be nice to know if there is an API that does this?
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone 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

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 my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
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.…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

752 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