I am implementing GetHashCode()
. I want to sum the values in a property called string Id
then divide
by some constant and return the result. I am using GetNumericValue()
:
int sum = 0;
foreach (var ch in Id)
sum += char.GetNumericValue(ch);
But it seems that GetNumericValue
returns double
. is it ok to convert it into an int
?
I thought that Unicode
characters are represented by whole number, why is double
returned?
And is it okay to ignore it?
Why is double returned?
While 0-9 are the standard digits, actually there are some Unicode characters that represent numbers, some of them are floating point like ⅔
or ½
. Let's get an example:
var ch = char.GetNumericValue('½');
Console.WriteLine(ch);// 0.5 output