User defined function not executing properly

I am trying to write a user defined function that will round a number UP to the nearest 1000. For example, 1786 would round to 2000. I just don't see where the code is going wrong, as it seems logical to me and the math works on paper. Any thoughts/suggestions would be appreciated. Thanks!!

lineSixAmount is a double variable from the main function.

1
2
3
4
5
6
7
8
9
10
11
double roundUp (double lineSixAmount)
{    
     double roundUpValue;
     
      roundUpValue = (lineSixAmount / 1000);
      roundUpValue = ceil(roundUpValue);
      roundUpValue = (roundUpValue * 1000);
      
return roundUpValue;
}
    
Last edited on
Your code rounds 1786 to 2000 for me.

But it also round 1001 to 2000. Is that what you want? (not really the nearest 1000)

1001 -> 1.001 -> 2.000 -> 2000
Last edited on
Yes, that was what I intended (my apologies if my use of nearest caused confusion).

Thank you for confirming that my function was working properly, I actually identified the problem as the function call, which I should have included in the original post.
Topic archived. No new replies allowed.