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. Maximum value display....

Maximum value display....

Scheduled Pinned Locked Moved C#
11 Posts 3 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.
  • G greendragons

    Hello everyone....i got struck while creating a numeric list of all numbers between 0 to 10 pow 100..... double supports till 308 but it prints like 1E+100 is there any way that i can get value in digits rather than 1E.....

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

    YourNumber.ToString("F"); is the only way I am aware of.

    It's not necessary to be so stupid, either, but people manage it. - Christian Graus, 2009 AD

    G 1 Reply Last reply
    0
    • D dan sh

      YourNumber.ToString("F"); is the only way I am aware of.

      It's not necessary to be so stupid, either, but people manage it. - Christian Graus, 2009 AD

      G Offline
      G Offline
      greendragons
      wrote on last edited by
      #3

      no not showing digits...it's displaying same 1E+100.....

      D 1 Reply Last reply
      0
      • G greendragons

        no not showing digits...it's displaying same 1E+100.....

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

        I just tried following code:

        string str = double.MaxValue.ToString("f");

        Works fine for me.

        It's not necessary to be so stupid, either, but people manage it. - Christian Graus, 2009 AD

        G 1 Reply Last reply
        0
        • D dan sh

          I just tried following code:

          string str = double.MaxValue.ToString("f");

          Works fine for me.

          It's not necessary to be so stupid, either, but people manage it. - Christian Graus, 2009 AD

          G Offline
          G Offline
          greendragons
          wrote on last edited by
          #5

          Thnx alot bro...:) it's workin great....but is there any way to get rid off those .00 at last....

          G 1 Reply Last reply
          0
          • G greendragons

            Thnx alot bro...:) it's workin great....but is there any way to get rid off those .00 at last....

            G Offline
            G Offline
            greendragons
            wrote on last edited by
            #6

            sry lol....actually it's representing a fixed digit....not that number i wanted.... double dl = Math.pow(10,100); i want to get dl in digits rather than E....and that max value one is showing some fixed digit that also float it has .00 at last....

            D 1 Reply Last reply
            0
            • G greendragons

              sry lol....actually it's representing a fixed digit....not that number i wanted.... double dl = Math.pow(10,100); i want to get dl in digits rather than E....and that max value one is showing some fixed digit that also float it has .00 at last....

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

              This would help: Math.Pow(10, 100).ToString("f0"); The digit after "f" specifies number of digits after decimal.

              It's not necessary to be so stupid, either, but people manage it. - Christian Graus, 2009 AD

              G 1 Reply Last reply
              0
              • D dan sh

                This would help: Math.Pow(10, 100).ToString("f0"); The digit after "f" specifies number of digits after decimal.

                It's not necessary to be so stupid, either, but people manage it. - Christian Graus, 2009 AD

                G Offline
                G Offline
                greendragons
                wrote on last edited by
                #8

                the thing you told is good for printing 1 and 0's only...try this double dl = Math.Pow(10, 100);                   double dll = dl + 21;                   string ss = dll.ToString("f0");                   Console.Write(ss);                   Console.Read(); n tell how to work on that digit...it's not showing the change....

                1 Reply Last reply
                0
                • G greendragons

                  Hello everyone....i got struck while creating a numeric list of all numbers between 0 to 10 pow 100..... double supports till 308 but it prints like 1E+100 is there any way that i can get value in digits rather than 1E.....

                  L Offline
                  L Offline
                  Luc Pattyn
                  wrote on last edited by
                  #9

                  Hi, your problem is not related to the formatting string in some ToString() method, it is much more fundamental. real numbers are not capable of storing all the information that would be required to show all the digits of large numbers, that is exactly why they show at most 7 (float) or 16 (double) digits and tell you by which power of 10 the number needs to be multiplied. integers keep all information accurately until they reach their maximum value; for int (Int32) that would be around 2 billion, much less than what you want. To store your 10^100 value as an integer, one would need over 300 bytes, whereas regular integers only hold 4 or 8 bytes of data. decimals are somewhere in the middle, they won't solve it either. What you need is some special type, often called BigInt, BigInteger, BigNumber; google for those. There are some articles here on CodeProject about them. And C# 4.0 holds a class that could help you. :)

                  Luc Pattyn


                  Have a look at my entry for the lean-and-mean competition; please provide comments, feedback, discussion, and don’t forget to vote for it! Thank you.


                  Local announcement (Antwerp region): Lange Wapper? Neen!


                  G 1 Reply Last reply
                  0
                  • L Luc Pattyn

                    Hi, your problem is not related to the formatting string in some ToString() method, it is much more fundamental. real numbers are not capable of storing all the information that would be required to show all the digits of large numbers, that is exactly why they show at most 7 (float) or 16 (double) digits and tell you by which power of 10 the number needs to be multiplied. integers keep all information accurately until they reach their maximum value; for int (Int32) that would be around 2 billion, much less than what you want. To store your 10^100 value as an integer, one would need over 300 bytes, whereas regular integers only hold 4 or 8 bytes of data. decimals are somewhere in the middle, they won't solve it either. What you need is some special type, often called BigInt, BigInteger, BigNumber; google for those. There are some articles here on CodeProject about them. And C# 4.0 holds a class that could help you. :)

                    Luc Pattyn


                    Have a look at my entry for the lean-and-mean competition; please provide comments, feedback, discussion, and don’t forget to vote for it! Thank you.


                    Local announcement (Antwerp region): Lange Wapper? Neen!


                    G Offline
                    G Offline
                    greendragons
                    wrote on last edited by
                    #10

                    Thnx alot....i don't wanna get into generating digits individually using multidimensional string array or char array and concatenating them......

                    1 Reply Last reply
                    0
                    • G greendragons

                      Hello everyone....i got struck while creating a numeric list of all numbers between 0 to 10 pow 100..... double supports till 308 but it prints like 1E+100 is there any way that i can get value in digits rather than 1E.....

                      L Offline
                      L Offline
                      Luc Pattyn
                      wrote on last edited by
                      #11

                      Oh, and one more thing:

                      greendragons wrote:

                      all numbers between 0 to 10 pow 100

                      assuming you meant integer numbers only, stored in memory this would take more memory than your system holds; printed on paper this will take more paper than would fit in your house; and if you were to generate somehow say 10^50 numbers each second (not sure how you would do that with a CPU running at a few 10^9 instructions per second), it would take you 10^50 seconds, which is longer than the universe has existed till now. So next time, do a little reality check before you set out for a project like this. :)

                      Luc Pattyn


                      Have a look at my entry for the lean-and-mean competition; please provide comments, feedback, discussion, and don’t forget to vote for it! Thank you.


                      Local announcement (Antwerp region): Lange Wapper? Neen!


                      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