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. Convert decimal value to exponential value

Convert decimal value to exponential value

Scheduled Pinned Locked Moved C#
csharp
5 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.
  • P Offline
    P Offline
    Pankaj Saha
    wrote on last edited by
    #1

    Hi, I have a decimal number. I need to convert this decimal value to exponential value. I have a vb.net code to convert from decimal to exponential value is Format(100000, #.0#E-##) . When I run this code in vb.net it returns 1.0E5 I need the same expression for the c#. I am using the following code String.Format("{0:E}", 100000) and its returns 1.000000E+005, but I need 1.0E5. The same for the another value String.Format("{0:E}", 0.000597), I need 5.97E-4 but it is returning 5.970000E-004. Does anyone let me know the right expression :confused:

    Pankaj

    D 1 Reply Last reply
    0
    • P Pankaj Saha

      Hi, I have a decimal number. I need to convert this decimal value to exponential value. I have a vb.net code to convert from decimal to exponential value is Format(100000, #.0#E-##) . When I run this code in vb.net it returns 1.0E5 I need the same expression for the c#. I am using the following code String.Format("{0:E}", 100000) and its returns 1.000000E+005, but I need 1.0E5. The same for the another value String.Format("{0:E}", 0.000597), I need 5.97E-4 but it is returning 5.970000E-004. Does anyone let me know the right expression :confused:

      Pankaj

      D Offline
      D Offline
      dan sh
      wrote on last edited by
      #2

      Use string.Format("{0:0.0E+00}", 1000000);.

      50-50-90 rule: Anytime I have a 50-50 chance of getting something right, there's a 90% probability I'll get it wrong...!!

      P 1 Reply Last reply
      0
      • D dan sh

        Use string.Format("{0:0.0E+00}", 1000000);.

        50-50-90 rule: Anytime I have a 50-50 chance of getting something right, there's a 90% probability I'll get it wrong...!!

        P Offline
        P Offline
        Pankaj Saha
        wrote on last edited by
        #3

        Thanks for your replay. When I run**

        string.Format("{0:0.0E+00}", 0.000597);

        **its return 6E-04 but I need 5.97E-4. I do not want to round the number.

        Pankaj

        P 1 Reply Last reply
        0
        • P Pankaj Saha

          Thanks for your replay. When I run**

          string.Format("{0:0.0E+00}", 0.000597);

          **its return 6E-04 but I need 5.97E-4. I do not want to round the number.

          Pankaj

          P Offline
          P Offline
          Pankaj Saha
          wrote on last edited by
          #4

          I have done some small changed in the expression and got the near of correct result

          string.Format("{0:0.0E2}", 0.000597);

          then its returns 5.97E-004. Can we remove 00 after the E ?

          Pankaj

          P 1 Reply Last reply
          0
          • P Pankaj Saha

            I have done some small changed in the expression and got the near of correct result

            string.Format("{0:0.0E2}", 0.000597);

            then its returns 5.97E-004. Can we remove 00 after the E ?

            Pankaj

            P Offline
            P Offline
            Pankaj Saha
            wrote on last edited by
            #5

            Got one solution

            string.Format("{0:#.0#E-00}", 1000000);

            Pankaj

            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