Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question Prevent a large number - "ToString()" to use "E+0" format

Discussion in 'Scripting' started by GuirieSanchez, Dec 5, 2022.

  1. GuirieSanchez

    GuirieSanchez

    Joined:
    Oct 12, 2021
    Posts:
    406
    I'm trying to convert an integer of 9 digits to a string, but I want the string to be in a plain format (0-9). When I use
    ToString();
    I get this format "xxxE+08".

    How could I adapt it? Is there any "ToString("n0")-like" method to prevent the string to use the "E+0" format?

    I tried to search for it here but I didn't see they address this specific use case.
     
    Last edited: Dec 5, 2022
  2. Bunny83

    Bunny83

    Joined:
    Oct 18, 2010
    Posts:
    3,915
    You want the fixed point format "F0"
    Alternatively you can use "D0", though this format only works with actual integer types and would throw an exception with double or float.
     
    GuirieSanchez likes this.
  3. GuirieSanchez

    GuirieSanchez

    Joined:
    Oct 12, 2021
    Posts:
    406
    I thought "ToString(F)"s methods were for decimal format. I guess F0 takes no decimal and also would prevent other formatting than numbers. Thank you!