hi there. I want to mimic the Excel ceiling function by always rounding UP the results of my formula to the nearest $5. I'm not able to use ceiling or int within the SQL expression. Also to let you know I am using Crystal 7.
I know we're using something old. I absolutely agree with you! I don't think this round function you're suggesting consistently rounds up. It also will round down to the nearest $5 which I don't want. Also, I'm using the round on a running total not on a straight field.
If {Table.field} is in integer perfectly divisible by 5, they don't want to add 5 to it. Your formula does not take that into account. I think the formula should be:
if remainder({table.field},5)=0 then
(truncate({table.field}/5)*5)+5 else
{table.field}
However this does not address how to treat negative numbers. Fancyface, any comment on negatives? Should -6 be represented as -5 or -10?
Software Sales, Training, Implementation and Support for Macola, eSynergy, and Crystal Reports
Good catch, Don. I tested the formula with positive and negative numbers, but not with whole numbers exactly divisible by 5. The following works for positive or negative numbers and accounts for this situation:
if {table.field} >= 0 and
remainder({table.field},5) <> 0 then
(truncate({table.field}/5)*5)+5 else
(truncate({table.field}/5)*5)
Don your Round(({database.field+2.4999}/5,0)*5 seems to be - pardon the pun - right on the money! I tested it over the weekend and compared it to the manual ceiling calculation in Excel and it mimics it exactly! I don't think negative numbers will be an issue in this case because the base will never be less than 0 in my case. I want to thank you so much for this formula. Bumping it up first the "half mark" is exactly the right logic. Thank you everyone for all your posts. It's a huge help. I know I'm so limited by version 7 but I have no choice on that one. So thank you!!
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.