| | |
floating point : overflow error
![]() |
•
•
•
•
get keyboard input as a string then do whatever you want with the individual digits.
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;
// More info: http://msdn2.microsoft.com/en-us/library/wyk4d9cy.aspx
Math.round(double number); // Round to the nearest integer
I've go to go to work, I'll post a function that will round a double number when I return.
Good luck, LamaBot
Back from work...
Here is a simple program that'll illustrate how to use strings to convert floating point values (represented as a string) to an integer:
Please not that the code is an illustration but might not be considered good programming in some views. I hope I helped.
Good luck, LamaBot
Here is a simple program that'll illustrate how to use strings to convert floating point values (represented as a string) to an integer:
c Syntax (Toggle Plain Text)
#include <stdlib.h> #include <stdio.h> int DoubleRound(char *fnum); int main() { char dnum[] = "92.45972340958723"; printf("%d",Double2Integer(dnum)); return 0; } int Double2Integer(char *fnum) { int integeri = atoi(fnum),i,j,k; char hex = 0x30; i=k=0; while (fnum[i] != '.') i++; j = strlen(fnum); for (;j>i;j--) { switch(fnum[j]) { case '5': case '6': case '7': case '8': case '9': while (fnum[j-1] != hex) hex++; hex++; fnum[j-1] = hex; break; } } switch(fnum[i+1]) { case '5': case '6': case '7': case '8': case '9': integeri++; break; } return integeri; }
Please not that the code is an illustration but might not be considered good programming in some views. I hope I helped.
Good luck, LamaBot
Last edited by Lazaro Claiborn; Feb 17th, 2007 at 12:39 am. Reason: formatting
![]() |
Similar Threads
- a simple way to print a binary representation of a floating point number? (C++)
- MIPS - convert integer to floating point?? (Assembly)
- Matlab - Is this a floating point arithmetic problem? (Computer Science)
- FLOATING POINT.......Please (C++)
- help needed in floating point (C++)
Other Threads in the C Forum
- Previous Thread: How to get status of a process
- Next Thread: bioskey()
| Thread Tools | Search this Thread |
#include adobe api array arrays asterisks binarysearch calculate char cm copyanyfile copyimagefile copypdffile cprogramme creafecopyofanytypeoffileinc createcopyoffile createprocess() csyntax database directory dynamic feet fflush fgets file fork forloop frequency getlasterror givemetehcodez global graphics gtkgcurlcompiling hacking hardware highest homework i/o include incrementoperators input interest kernel kilometer km linked linkedlist linux linuxsegmentationfault list locate logical_drives loopinsideloop. match matrix meter microsoft motherboard mqqueue mysql number odf open openwebfoundation owf pattern pdf performance pointer posix probleminc process program programming pyramidusingturboccodes radix read recursion recv repetition research scanf scheduling segmentationfault send sequential shape socket socketprograming stack standard string systemcall turboc unix user voidmain() wab win32api windows.h






