Search code examples
c#asp.netcrystal-reports

Crystal Report- how to round decimal in crystal report?


I am currently trying to round up the figure in my crystal report but the round function in crystal report does not change it to correct figure.

If the amount is 32,000, I want to convert it to 40,000 by rounding. If the amount is 24,000, I want to convert it to 30,000,

Is there any way to do this such rounding?


Solution

  • You can do something like:

    int num = 32000;
    string textNum  = num.ToString();
    //count number of zero
    int countZero = textNum.Length - textNum.TrimEnd('0').Length;
    //get a divisor to get a fraction
    double divisor = (int)Math.Pow(10, (countZero + 1));
    double firstDiv = num / divisor;
    int val = (int)(Math.Ceiling(firstDiv) * divisor);
    

    Hope that will help :)