Search Unity

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,092
    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,595
    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.