How to convert Arabic number to int?

前端 未结 6 2079
一向
一向 2020-12-05 14:26

I work on a project in C# which requires to use arabic numbers, but then it must store as integer in database, I need a solution to convert arabic numbers into int in C#. An

6条回答
  •  渐次进展
    2020-12-05 14:59

    to get the value of a digit, substract the zero character from it, e.g in normal numeric, '1'-'0' = 1, '2'-'0' = 2. etc.

    For multidigit number you can use something like this

     result =0;
     foreach(char digit in number)
     {
         result *= 10; //shift the digit, multiply by ten for each shift
         result += (digit - '0)'; //add the int value of the current digit.
     }
    

    just replace the '0' with the arabic zero if your number uses Arabic character. This works for any numeric symbols, as long as 0-9 in that symbol system are encoded consecutively.

提交回复
热议问题