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. C#
  4. Format string for fixed length real value in scientific representation?

Format string for fixed length real value in scientific representation?

Scheduled Pinned Locked Moved C#
cssquestion
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.
  • M Offline
    M Offline
    Mats Euren
    wrote on last edited by
    #1

    Hi! I'm looking for a format string (to String.Format()) which is capable of handling the following criterias: My input is a real value like -0.00123456 or 1233456.134 etc. I want the output in scientific representation like "-1.234560E-003". I want the output string to ALWAYS be 14 chars long no matter what. How does the correct format string to accomplish this look like? I've tried "{0:E7}" for positive values and "{0:E6}" for negative values. But this doesn't cover values greater than 9.9999999E+999 and values less than 1.0E-999.

    C 1 Reply Last reply
    0
    • M Mats Euren

      Hi! I'm looking for a format string (to String.Format()) which is capable of handling the following criterias: My input is a real value like -0.00123456 or 1233456.134 etc. I want the output in scientific representation like "-1.234560E-003". I want the output string to ALWAYS be 14 chars long no matter what. How does the correct format string to accomplish this look like? I've tried "{0:E7}" for positive values and "{0:E6}" for negative values. But this doesn't cover values greater than 9.9999999E+999 and values less than 1.0E-999.

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      I suspect that means you need a great level of accuracy than C# offers. Are you using the floats, Decimals or doubles ? You may need a scientific library of some sort.

      Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.

      M 1 Reply Last reply
      0
      • C Christian Graus

        I suspect that means you need a great level of accuracy than C# offers. Are you using the floats, Decimals or doubles ? You may need a scientific library of some sort.

        Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.

        M Offline
        M Offline
        Mats Euren
        wrote on last edited by
        #3

        Well, the probability that I get values less than E-999 or greater than E+999 is more or less zero, but I thought that it would be cleaner if I could handle both positive and negative values with one format string. I use doubles, but thats not carved in stone...

        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