• 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:
danny1979
1 Solution
 
emadatCommented:
If you mean to the nearest second digit then:
Result := Round(your_number*10) / 10;
0
 
sfockCommented:
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
 
luisseixasCommented:
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
ILECommented:
this is a coplete solution

function round05(a:real):real;
begin
round05:=round(a*20)/20;
end;
0
 
ILECommented:
this is a coplete solution

function round05(a:real):real;
begin
round05:=round(a*20)/20;
end;
0
 
brownberryCommented:
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

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!

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