Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. .NET (Core and Framework)
  4. Formatting with Minimum and Maximum Places

Formatting with Minimum and Maximum Places

Scheduled Pinned Locked Moved .NET (Core and Framework)
tutorialquestion
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    Brady Kelly
    wrote on last edited by
    #1

    I can't seem to find a way to format a float, to always have at least two places, but will include up to n places when required, i.e. it will render three places if required, but no trailing zero when only two places are required. Then, why is my number always rounded to two places in the following example?              float f = 22223.430321F;             MessageBox.Show(string.Format("{0:0.0000}", f));

    D 1 Reply Last reply
    0
    • B Brady Kelly

      I can't seem to find a way to format a float, to always have at least two places, but will include up to n places when required, i.e. it will render three places if required, but no trailing zero when only two places are required. Then, why is my number always rounded to two places in the following example?              float f = 22223.430321F;             MessageBox.Show(string.Format("{0:0.0000}", f));

      D Offline
      D Offline
      drweb86
      wrote on last edited by
      #2

      Have you seen this article? http://www.csharp-examples.net/string-format-double/[^]

      B 1 Reply Last reply
      0
      • D drweb86

        Have you seen this article? http://www.csharp-examples.net/string-format-double/[^]

        B Offline
        B Offline
        Brady Kelly
        wrote on last edited by
        #3

        No, thanks. I've since learned that the default for float is rounding to two places, regardless of formatting, and I missed the conversion from SQL float to CLR double. I can work with a double as expected.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups