I have a int x.ToString(); drawn on the screen with SpriteFont. If the int goes negative the minus evaluates to different char depending on the device.
(int)x.ToString().ToCharArray()[0] becomes:
45 on Desktop and the Android emulator but 8722 on my Android hardware (Galaxy s22 ultra)
out of interest … is the problem, that the char code is not what you expect or that it is drawn wrong on the screen?
(int)x.ToString()
is different than
((int)x).ToString()
the first casts the result of “tostring()” to int (most likely not what you want or in your example you’re casting the char on index 0 to int), the second one casts x to int first and makes toString on that (which calls Int32.ToString instead of float.ToString or whatever x is)
you can also just output the float directly via x.ToString(“0”)
PS: 8722 is the unicode decimal code for the minus sign “-” so I am not really sure how the cultureinfo did change anything … maybe because android puts out “−” and if you cast that to int you may end up with 8722 … as you are casting the char to int not x
Possibly the Galaxy s22 ultra has the Language/Region set to something other that English/US.
Some cultures use formatting that has characters outside the safe ASCII range.
the char datatype represents a 16 bit unicode character - it’s not ASCII … one would first need to ASCIIEncode to make sure to get an ASCII value … which is then used for lookup by the DrawString Method (as those most likely work with ASCII values not sure if Font libraries allow for alias or full unicode referencing?)
Looks like on that Android Phone the culture forces the string “-” to be encoded in full unicode and that code is then not found in the font