We are excited to announce that the ASP.NET Forums are moving to the new Microsoft Q&A experience. Learn more >

# C# - How to find adjust and round value from given range in another table[Answered] RSS

## 2 replies

Last post Nov 02, 2017 10:54 AM by gani7787

• gani7787

Member

209 Points

701 Posts

### C# - How to find adjust and round value from given range in another table

How to find adjust and round value from given range in another table.

I have below values.

[0] SUB A=140
[1] SUB C=60

The above values needs to be check in the below TABLE B.

 Dept SUB A SUB B SUB C A1 A2 A3 100 A4 25 A5 A6 50 A7 A8 A9 25 A10 A11 A12 10

For example,

let us consider SUB A=140

First we need to find the columns in TABLE A along with Dept=A3 rows (A3 is parameter which we need to pass finding column along with this)

My objective is find the range in table and adjust the value near to this based on my range.

For example,

My SUB A=140

my selected range is "100"

So the Final result is nearest value of SUB A=200 (it means it will consider the range is 100 200,300,etc)

If SUB B=220 then final value is SUB A=300

For Second one,

SUB C=60 ==> Final value is SUB C=75 (the range statrts from 25,50,75,etc)

Final Output

[0]SUB A=200

[1]SUB C=75

How to write a code in C# or LINQ in C#..?

• Billy Liu

Contributor

2260 Points

815 Posts

### Re: C# - How to find adjust and round value from given range in another table

Nov 02, 2017 02:59 AM|Billy Liu|LINK

Hi gani7787,

For example:

```        static void Main(string[] args)
{

int SubA = 120;
int SubB = 65;
int RoundA = 100;
int RoundB = 25;
Console.WriteLine(GetRound(SubA, RoundA));
Console.WriteLine(GetRound(SubB, RoundB));

}

static int GetRound(int Sub, int Round)
{
int value = ((Sub / Round)+1)*Round;

return value;
}```

Best Regards,

Billy

MSDN Community Support
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.
• gani7787

Member

209 Points

701 Posts