Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only. On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live. Read our full announcement for more information and let us know if you have any questions.

Bug using SetText with a {0:0.#} format doesn't work as expected

Discussion in 'UGUI & TextMesh Pro' started by MaskedMouse, Aug 10, 2021.

  1. MaskedMouse

    MaskedMouse

    Joined:
    Jul 8, 2014
    Posts:
    1,094
    I have a
    float
    that I'm passing to the
    TextMeshProUGUI
    component using
    SetText
    . It doesn't seem to work the same as
    string.Format
    where the # is optional.
    If the number is 5.0 it'll show as 5. With TMPro it shows as #5.
    I tried using
    {0:0.0}
    as format but it always shows the
    .0
    .
     
  2. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,596
    The SetText() function has limited formatting support where as such it doesn't offer all the functionality of string.Format.

    I will try to take a closer look at SetText() over the next week or so and see if I can add some additional formatting functionality to it.
     
    MaskedMouse likes this.