Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct here to familiarize yourself with the rules and how to post constructively.

  2. Unity 2022.1 is now available as the latest Tech release.
    Dismiss Notice
  3. Improve your project's performance with our new guide on profiling in Unity.
    Dismiss Notice

String format not working as expected

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

  1. neufoctobre

    neufoctobre

    Joined:
    Jun 20, 2015
    Posts:
    85
    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:
    85
    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:
    321
    Try
    Code (csharp):
    1. ToString("#,##0", CultureInfo.InvariantCulture)
     
  4. neufoctobre

    neufoctobre

    Joined:
    Jun 20, 2015
    Posts:
    85
    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:
    321
  6. neufoctobre

    neufoctobre

    Joined:
    Jun 20, 2015
    Posts:
    85
    Thanks !
     
unityunity