Format display of float variables

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • John

    Format display of float variables

    Hi,

    I have varaiables declared as float, the result of .ToString() is like
    1.0000. How can I get rid of the 0s in the decimal? e.g. 1.0000 will be 1
    and 1.3500 will be 1.35

    TIA


  • Morten Wennevik

    #2
    Re: Format display of float variables

    Hi John,

    1.0000f is displayed as 1, and 1.3500 f is displayed as 1.35 (or rather
    1,35 on my computer), using a regular ToString().

    You can format the output in a number of ways, but empty zeroes will be
    stripped by default, unless you specify them in a format.

    Some formatting samples




    On Tue, 05 Sep 2006 20:59:24 +0200, John <someone@micros oft.comwrote:
    Hi,
    >
    I have varaiables declared as float, the result of .ToString() is like
    1.0000. How can I get rid of the 0s in the decimal? e.g. 1.0000 will
    be 1
    and 1.3500 will be 1.35
    >
    TIA
    >
    >


    --
    Happy Coding!
    Morten Wennevik [C# MVP]

    Comment

    Working...