# Math question: latitude display

I have the following code that displays the given latitude value in a certain format. I want the code to display it in a changed format:
DDMMSS.SS

Example: 230521.73,N where N23d-05m-21.73s is the actual latitude. BTW, AnsiString is a C++ Builder class and if you don't know, just ignore it.

Current code:
AnsiString latitudeDisplay(double aValue) {
char buf[80];
double dValue = aValue * 180. / M_PI;
int ival = (int)dValue;
double fval = fabs(dValue - ival)*60.;
ival = abs(ival);
sprintf( buf, "%2.2i%08.5lf,%c", ival, fval, (dValue>=0)?'N':'S' );
return AnsiString(buf);
}

I guess, I can do it myself but getting it done here would be a double-confirmation. If I am correct, the current code shows the degrees in the first two digits but seconds in the rest of the digits. For the change, the seconds have to be broken into minutes first. Right?

I am giving 100 points here as I want the changed code itself.
###### Who is Participating?

progCommented:
char *  latitudedisplay(double aValue,char* buf) {
int mins;
double secs;
double dvalue = aValue * 180.0 / 3.141592654 * ((aValue>=0)? 1.0:-1.0);

int ival = (int)dvalue;

mins = (int) ((dvalue - (double) ival)*60.0);

secs = ((dvalue - ival) - (double) mins /60.0) * 3600.0;
ival = abs(ival);
sprintf( buf, "%2.2i %2.2i %f %c", ival, mins,secs, (aValue>=0)?'N':'S' );
return buf;
}

main()
{
char buf[80];
printf("\n%s",latitudedisplay(-.5654544,buf));
getch();
}
0

progCommented:
In any case

double dseconds=(fabs(dValue) * 60.0 - floor(fabs(dValue) * 60.0)) * 60.0;

extracts the number of seconds from a double value in degrees

0

Author Commented:
Thanks!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.