Format specifier for double and lond double in C

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • amarniit
    New Member
    • Sep 2009
    • 13

    Format specifier for double and lond double in C

    I am making a project on the basis of numbers........ here i need that i print a bigger number whose lenght is more than 300 digits....... while i am doing it in C than i am getting a problem my all digit convert in base of "e" and i get the number in this format 1.2222222222222 222222222222222 222222000000000 000000000000000 0000000000000e+ 127
    but i need that my number will displayed as 1.2222222222222 222222222222222 222222222222222 222222222222222 222222222222222 222222222222222 222222222222222 222222222222222 222222222222222 222222222222222 222222222222222 222222222222222 222222222222222 222222222222222 222222222222222 222222222222222 222222222222222 222222222222222 222222222222222 222222222222222 222222222222222 222222222222222 222222222222222 222222222222222 222222222222222 222222222222222 222222222222222 222222222222222 222222222222222 22222222222222
    means whatever user enter its not matter but all digits must be print as it is..... may be any of lenght....... now how can i do this.....
    i heard that ranhge of double is 10^+308 and long double is 10^+4092
    but i dont know the format specifier of it.... and will they print the whole number accoring to their range........ plase help..........
    Last edited by RedSon; Nov 3 '09, 03:41 PM. Reason: Phone number? Seriously? Comeon people! It's the internet!
  • donbock
    Recognized Expert Top Contributor
    • Mar 2008
    • 2427

    #2
    The C Standard Library does not support formatted I/O of 300-digit numbers. You will have to write your own functions to do this.

    Comment

    • Banfa
      Recognized Expert Expert
      • Feb 2006
      • 9067

      #3
      And you will not be able to use any basic floating point type such as float, double or long double because they may have the range to store the numbers you are interested in but they do not have the precision.

      Comment

      • Ectara
        New Member
        • Nov 2009
        • 24

        #4
        If you were to do so, you could start by outputting the number digit by digit, starting with the most significant in a loop. Keep in mind, floating point inaccuracies will occur. IIRC, float can accurately store 6 digits, and double accurately stores 15 digits, mantissa included. Anything outside of that, could be anything.

        Comment

        Working...