| TIP: Click on subject to list as thread! | ANSI |
| echo: | |
|---|---|
| to: | |
| from: | |
| date: | |
| subject: | (double) a/b |
JG> int a,b,;
JG> double u,z;
JG> z = (double) a/b;
JG> /* what's the purpose of the "()" on double here? */
JG> u = (double) (a/b);
JG> /* what's the purpose of the 2 "()" here? */
a and b are integer values. In order to preserve the decimal
portion of the quotient, you need to explicitly cast it to
type. Otherwise, the remainder will be lost.
If you want to see the difference it makes, then run an
example program. In the first instance, a will be cast to
double, but not b, and in the second, the quotient will be
cast to double.
#include
int main(void)
{
int a, b;
printf("(double)a/b = %f\n", (double)a / b);
printf("(double)(a/b) = %f\n", (double)(a / b));
return 0;
}
> ] * Origin: *YOPS ]I[* 8.4 GIG * RA/FD/FE * Milwaukee, WI (1:154/750)SEEN-BY: 396/1 622/419 632/0 371 633/260 267 270 371 634/397 635/506 728 810 SEEN-BY: 639/252 670/213 218 @PATH: 154/750 222 396/1 633/260 635/506 728 633/267 |
|
| SOURCE: echomail via fidonet.ozzmosis.com | |
Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.