•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the C section within the Software Development category of DaniWeb, a massive community of 456,586 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,624 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C advertiser: Programming Forums
Views: 1436 | Replies: 3 | Solved
![]() |
•
•
Join Date: Oct 2006
Posts: 60
Reputation:
Rep Power: 3
Solved Threads: 0
unsigned long nBolum = 0L;
unsigned long nKalan = 0L;
unsigned long ulA = 0L;
unsigned long ulB = 0L;
...
printf("ulA=%u\n",ulA);
printf("ulB=%u\n",ulB);
nBolum = (unsigned long) ulA/ulB;
nKalan = (unsigned long) ulA%ulB;
printf("nBolum = %u\n",nBolum);
printf("nKalan = %u\n",nKalan);
printf("HVFE.c exiting\n");
exit(1);it prints :
ulA=2607503366 ulB=16777215 nBolum = 65435 nKalan = 7100321
but nBolum must be 155.419.... Why is this happenning?
thanx.
You can't possibly get 155.419 from an unsigned long, there is no decimal point from integers. You need float or double.
And dividing two integers always gives an integer, even if you load it into a floating point number. For example:
12.000 is loaded into dval, not 12.5.
And dividing two integers always gives an integer, even if you load it into a floating point number. For example:
c Syntax (Toggle Plain Text)
double dval; dval = 25/2;
Got a cough? Go home tonight and eat a whole box of Ex-Lax. Tomorrow, you'll be afraid to cough.
-- Pearl Williams
-- Pearl Williams
•
•
Join Date: Oct 2006
Posts: 60
Reputation:
Rep Power: 3
Solved Threads: 0
•
•
•
•
You can't possibly get 155.419 from an unsigned long, there is no decimal point from integers. You need float or double.
And dividing two integers always gives an integer, even if you load it into a floating point number. For example:
12.000 is loaded into dval, not 12.5.c Syntax (Toggle Plain Text)
double dval; dval = 25/2;
i want to get 155 as integer.
•
•
Join Date: Oct 2006
Posts: 60
Reputation:
Rep Power: 3
Solved Threads: 0
•
•
•
•
unsigned long nBolum = 0L; /* I have changed this line to : */ /* unsigned int nBolum = 0; */ unsigned long nKalan = 0L; unsigned long ulA = 0L; unsigned long ulB = 0L; ... printf("ulA=%u\n",ulA); printf("ulB=%u\n",ulB); nBolum = (unsigned long) ulA/ulB; /* I have changed this line to : */ /* nBolum = (unsigned int) ulA/ulB;*/ nKalan = (unsigned long) ulA%ulB; printf("nBolum = %u\n",nBolum); printf("nKalan = %u\n",nKalan); printf("HVFE.c exiting\n"); exit(1);
it prints :
to the screen.ulA=2607503366 ulB=16777215 nBolum = 65435 nKalan = 7100321
but nBolum must be 155.419.... Why is this happenning?
thanx.
change the line above and nBolum problem is gone. But I also see that nKalan is not being calculated correctly. I have opened another topic for the problem.
![]() |
•
•
•
•
•
•
•
•
DaniWeb C Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Similar Threads
- Problem regarding storing value into unsigned int (C)
- a simple C program to create/open/write/close files generaing basic arithmetic ops (C)
- Range Of Long?? (C++)
- text to numbers, numbers to text (C)
- Winsock Multi-Client Servers (C++)
Other Threads in the C Forum
- Previous Thread: Please help me with EXTERN usage
- Next Thread: unsigned long % operation



Linear Mode