• Status: Solved
• Priority: Medium
• Security: Public
• Views: 730
• Last Modified:

Rounding to the nearest 0.05

This question should be easy, how do you round a variable up or down to the nearest 0.05

Thanks

Dan
0
danny1979
Asked:
1 Solution

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

Commented:
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

Commented:
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

Commented:
this is a coplete solution

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

Commented:
this is a coplete solution

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

Commented:
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

Tackle projects and never again get stuck behind a technical roadblock.