Convert percent (1 ~ 100) to a range of (0 ~ 9)

Peter Volz 1,295 Reputation points
2023-10-24T09:54:59.0233333+00:00

Hello all,

Since the forum's bug still exists and most of the times we cannot reply to our own thread:

https://learn.microsoft.com/en-us/answers/questions/1402693/convert-percent-to-a-range-of-0-9

I've been given a method by @Jiachen Li-MSFT :

CInt(Math.Floor((percentage - 1) / 10))

But in this method 100 is expected to return 10 while it returns 9.

Actually any value more than 91 will return 9...

Developer technologies | VB
Developer technologies | C#
{count} votes

Accepted answer
  1. Jiachen Li-MSFT 34,221 Reputation points Microsoft External Staff
    2023-10-24T10:01:40.11+00:00

    Hi @Peter Volz ,

    Since 1~100 corresponds to 0~9 in your previous description, the code I provided is 1~10 corresponds to 0, 11~20 corresponds to 1, and so on.

    You can remove -1 from the code so that 0~9 corresponds to 0, and 10~19 corresponds to 1.

    Best Regards.

    Jiachen Li


    If the answer is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. Peter Volz 1,295 Reputation points
    2023-10-24T10:12:48.56+00:00

    oops, seems this works:

    Convert.ToInt32(percentage / 10)

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.