views:

76

answers:

1

hi, i am looking to put together some logic to look at a particular number and based on a simple calulcation tell me what another number is. Example - lets say that i have a string of characters and each 50 characters will increment an integer by 1. so if i have 0 - 49 chars, counter = 1, if i have 50-99 chars, counter = 2, if i have 100 - 149 chars, counter = 3.

i thought i could do this by converting everything to type int but that doesnt work as sometimes it will round down when it should always round up - i.e. (int)(charCount / 50).

Im wondering if i have to use the modulus operator. Any suggestions?

+1  A: 

For this exact example, you can just increment the counter after your division, so:

int counter = (int)(stringToCheck.Length / 50) + 1
Ryan Brunner
thanks Ryan works well.
Grant