Hi!
can somebody please tell me how to avoid floating point overflow error? Mine is a very big program that uses double data type.
Is there any way in which I can roundoff double numbers to upto certain digit?
get keyboard input as a string then do whatever you want with the individual digits.
He didn't specify that the floating point number was inputed off the command line, but the string idea will work nonetheless as long as you enumerate through the string until you reach the "." character after which you can convert the character(s) number(s) into an integer and proceed to the logical operations that determine if a one should be added or not.
However, if you're true reason for rounding is so that you have a percise number to output than you should wait until you're about to output it and can use, but no limited, to one of the following:
// If you want to display 2 digits passed the decimal point
C - printf("%.2f", floatingNumber);
// same as above but using the C++ standard library
C++ - cout << "Set percision: " << setpercision(number) << DoubleNumber;
No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.