Doubt in C
Anyway, this is my doubt:
i couldn't find this in Google.......
---> if we declare a float, like:
float a=2.7;
it gets stored in the memory as 2.700000 with specifically 6 digits only, after the decimal point. Why? (may be related to its format)
U can set any precision using setprecision! Don't try large numbers or ur terminal might hang! I tried "100000000000" as precision and had to kill the program then!! ;)
Buddy, abhi_10_20 is talking about C. Your code is C++! :)
Anyway, this is my doubt:
i couldn't find this in Google.......
---> if we declare a float, like:
float a=2.7;
it gets stored in the memory as 2.700000 with specifically 6 digits only, after the decimal point. Why? (may be related to its format)
It's predefined in the compiler. This is probably the wrong sect. it shud go in s/w troubleshooting. :)
but still not satisfied somewhat...
i think it goes with the storage space reserved........like float requires 4 bytes
in a standard turbo c compiler.....and we need to do some 'masala munch' with these 4 bytes.....
Or u better start trusting the replies in here .. Shilesh is perfectly correct .. it's 6 point precision by default and u cannot do anything about it if u want the value just 1 or 2 places do it just like it's written .. change the precision of output wid
printf("salary is %.3fn", salary );
being more clear this will print upto 3 places after decimal if u write
printf("salary is %.2fn", salary );
this prints 2 values and so on ..
:shock: this book is "W. Kernighan and Dennis M. Ritchie" is it not a voilation.. if so then remove the link please..
#include
#include
int main()
{
int p;
cout<<"Mediator asked to enter precision u wanna set : "; cin>>p;
double x(3.14);
cout <<"x = "<
}
U can set any precision using setprecision! Don't try large numbers or ur terminal might hang! I tried "100000000000" as precision and had to kill the program then!! ;)
man...i can start a big library with my pdf's....
But if you want it to 3 point decimal than use %.3f in the print statement to get result in upto 3 place of decimal
e.g.
printf("salary is %.3fn", salary );
For in depth Knowledge read Dennis Ritche
Same book i was talkin about..
in the pdf mentiontioned page number 22 gives the idea about your problem
man...i can start a big library with my pdf's....
Ha hA ha ha. :lol:
I don't know. It was given to me by a frnd. :?:
ok. :)
i have uploaded it. :)
__________
After giving the captcha code, wait 30 secs. goto the bottom. when the downlaod now button gets activated, click it to download. Don't use any d/w manager. :)
__________
Was it useful? :)
#If you have any other info about this subject , Please add it free.# |