Search Unity

String format not working as expected

Discussion in 'Android' started by neufoctobre, Feb 4, 2019.

  1. neufoctobre

    neufoctobre

    Joined:
    Jun 20, 2015
    Posts:
    94
    Hi everyone,

    I have an issue when I try to convert an int into string using this code :

    Integer.ToString ("#,##0");

    This line return me an empty space instead of a comma.For example let's take an integer int = 2000. When I print the line above, the result is "2 000" and the result expected is "2,000".

    This code was working before Unity 2018, I supposed before I update to .Net 4 but I'm not sure.
    Does someone already had this kind of issue and is it possible the new .Net broke something ?

    Thank you !
     
  2. neufoctobre

    neufoctobre

    Joined:
    Jun 20, 2015
    Posts:
    94
    Wow, my last 6 posts on the Unity forum didn't get any answer.

    Is this forum dead ??
     
  3. drcrck

    drcrck

    Joined:
    May 23, 2017
    Posts:
    328
    Try
    Code (csharp):
    1. ToString("#,##0", CultureInfo.InvariantCulture)
     
  4. neufoctobre

    neufoctobre

    Joined:
    Jun 20, 2015
    Posts:
    94
    Thank you so much !!! Its working !

    What does the "CultureInfo.InvariantCulture" is doing ? Because without this and previous version of Unity it was working without this
     
  5. drcrck

    drcrck

    Joined:
    May 23, 2017
    Posts:
    328
  6. neufoctobre

    neufoctobre

    Joined:
    Jun 20, 2015
    Posts:
    94
    Thanks !