Mail Archives: djgpp/1998/01/20/08:25:32
Rikard Björklind wrote:
>
> I want to know how to assign a double value to an int. Like this for
> example:
>
> int hej = (PI*sin(34)/43);
>
> I want the value rounded. Please help me I'm a beginner =).
hej,
first of all, this is a basic C question and hence off-topic. you should
give news:comp.lang.c and/or news:comp.lang.c.moderated a try in the
future, and while you are at it, download the C faq also. in any case,
now that you are here, note the following:
* in ANSI C, arguments to the trigonometric functions are given in
radians, not degrees (360 degrees = 2*PI radians). the header math.h
defines the constants M_PI (180 dg), M_PI_2 (90 dg) and M_PI_4 (45 dg),
use those.
* the best way to proceed depends on what you understand by rounding. if
d is a double value, (int)(d+0.5) is usually reasonable. you might also
want to look at the documentation for floor and ceil functions to see if
that is the functionality you are looking for.
hth.
--
----------------------------------------------------------------------
A. Sinan Unur
Department of Policy Analysis and Management, College of Human Ecology,
Cornell University, Ithaca, NY 14853, USA
mailto:sinan DOT unur AT cornell DOT edu
http://www.people.cornell.edu/pages/asu1/
- Raw text -