Even by editing the string afterwards, there is still the comma as
seperator.
text_team1.text = em.team1Score.ToString("#,##0");
text_team1.text.Replace(',','.');
You forgot to assign the replaced string back.
text_team1.text = text_team1.text.Replace(',','.');
EDIT:
If you still prefer a solution without using the Replace
function, you can use the Extension method below. It works for strings
and ints
. Please Google and read about extension methods if you don't know how they work.
Create and place the ExtensionMethod
script in any folder in your project:
using System.Globalization;
using System;
public static class ExtensionMethod
{
public static string formatStringWithDot(this string stringToFormat)
{
string convertResult = "";
int tempInt;
if (Int32.TryParse(stringToFormat, out tempInt))
{
convertResult = tempInt.ToString("N0", new NumberFormatInfo()
{
NumberGroupSizes = new[] { 3 },
NumberGroupSeparator = "."
});
}
return convertResult;
}
public static string formatStringWithDot(this int intToFormat)
{
string convertResult = "";
convertResult = intToFormat.ToString("N0", new NumberFormatInfo()
{
NumberGroupSizes = new[] { 3 },
NumberGroupSeparator = "."
});
return convertResult;
}
}
Usage:
string stringToFormat = "1234567890";
Debug.Log(stringToFormat.formatStringWithDot());
Or
int intToFormat = 1234567890;
Debug.Log(intToFormat.formatStringWithDot());
Or
string stringToFormat = "1234567890";
text_team1.text = stringToFormat.formatStringWithDot();
Use each one depending on which scenario you run into.