# Converting a Double to an Integer

Page 1 of 1

## 1 Replies - 1966 Views - Last Post: 04 October 2006 - 07:58 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'https://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=19232&amp;s=dfe2500c42d0bb268b1e80b5d365fe96&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 jaclyn_85

Reputation: 0
• Posts: 17
• Joined: 16-September 06

# Converting a Double to an Integer

Posted 03 October 2006 - 06:02 PM

In order for the last part of my calculations to work, starting with lc = jdn;
i need to first conver jdn which is a double into an integral type, but am not sure how to do this... please help.

```#include <stdio.h>

int main()
{
double jdn, tm;
long lc, nc, ic, jc;
int day, month, year, hours, minutes, seconds, a, b, meridian;

/*print title*/

printf(" * * Julian Date Conversion * *\n");

/*ask user for a Julian date */

printf ("Please enter a Julian Date:\n");
scanf("%lf", &jdn);

if (jdn <= 2299160)
printf ("Error: You have entered an invalid number.");

/* Perform calculations */
lc = jdn + 68569;
nc = 4 * lc / 146097;
lc = lc - (146097 * nc + 3) / 4;
ic = 4000 * (lc + 1) / 1461001;
lc = lc - 1461 * ic / 4 + 31;
jc = 80 * lc / 2447;
day = lc - 2447 * jc / 80;
lc = jc / 11;
month = jc + 2 - 12 * lc;
year = 100 * (nc - 49) + ic + lc;

lc = jdn;
tm = jdn - lc;
hours= jdn * 24;
a= jdn % 60;
minutes= a * 60;
b= minutes % 60;
seconds= b * 60;

if (meridian >= 12)
printf ("p.m.");
else printf ("a.m.");

/* print date*/

printf("%d %d %d %d %d %d %d\n", month, day, year, hours, minutes, seconds,
meridian);
return 0;
}

```

This post has been edited by jaclyn_85: 03 October 2006 - 07:16 PM

Is This A Good Question/Topic? 0

## Replies To: Converting a Double to an Integer

• g+ + -o drink whiskey.cpp

Reputation: 250
• Posts: 13,507
• Joined: 12-July 02

## Re: Converting a Double to an Integer

Posted 04 October 2006 - 07:58 AM

Are you speaking of integrals, or integers? You've mentioned both. If the answer is integers, dou you need to round the double to the nearest integer, or simply truncate?