Connecting Tech Pros Worldwide Forums | Help | Site Map

Format specifier for double and lond double in C

amarniit's Avatar
Newbie
 
Join Date: Sep 2009
Posts: 3
#1: 3 Weeks Ago
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.222222222222222222222222222222222200000000000000 00000000000000000000000e+127
but i need that my number will displayed as 1.222222222222222222222222222222222222222222222222 22222222222222222222222222222222222222222222222222 22222222222222222222222222222222222222222222222222 22222222222222222222222222222222222222222222222222 22222222222222222222222222222222222222222222222222 22222222222222222222222222222222222222222222222222 22222222222222222222222222222222222222222222222222 22222222222222222222222222222222222222222222222222 2222222222222222222222222222222222222222222222222
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..........

Expert
 
Join Date: Mar 2008
Location: Naperville, Illinois U.S.
Posts: 831
#2: 3 Weeks Ago

re: Format specifier for double and lond double in C


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.
Banfa's Avatar
AdministratorVoR
 
Join Date: Feb 2006
Location: South West UK
Posts: 6,206
#3: 3 Weeks Ago

re: Format specifier for double and lond double in C


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.
Newbie
 
Join Date: Nov 2009
Posts: 20
#4: 3 Weeks Ago

re: Format specifier for double and lond double in C


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.
Reply

Tags
amarniit, double, format specifier


Similar C / C++ bytes