Home » excel » asp.net – ROUNDUP(700.25;-1) returns 710, how to we do this in C#

asp.net – ROUNDUP(700.25;-1) returns 710, how to we do this in C#

Posted by: admin May 14, 2020 Leave a comment

Questions:

I am building an Application based on a excel sheet, at a certain point the sheet uses
=ROUNDUP(701.25;-1) which is returned as 710… how do we do this in C#

I tried Math.Round that returns 701, If I try to use Math.Round() with -1 then i get this

Rounding digits must be between 0 and 15, inclusive.

Please help me out here.

How to&Answers:

Try this (you’ll need to cast the return value to int if necessary):

public static double RoundUp(double value, int digits)
{
    double pow = Math.Pow(10, digits);
    return Math.Ceiling(value * pow) / pow;
}

This should give you the functionality defined here:

http://office.microsoft.com/en-gb/excel-help/roundup-HP005209242.aspx

Answer:

use the below two methods.Which may help you

int RoundUp(int toRound)
{
     return (10 - toRound % 10) + toRound;
}

int RoundDown(int toRound)
{
    return toRound - toRound % 10;
}

Referenece
Rounding integers to nearest multiple of 10