Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

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,064
    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

    Unity Technologies

    Joined:
    Feb 26, 2017
    Posts:
    6,588
    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.