Solved

# Rounding to the nearest 0.05

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

Thanks

Dan
0
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

LVL 3

Expert Comment

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

LVL 3

Expert Comment

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

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

R -> Result

R := round(N*20)/20;
0

LVL 3

Expert Comment

ID: 8011826
this is a coplete solution

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

LVL 3

Accepted Solution

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

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

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
Course of the Month11 days, 9 hours left to enroll