Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Math question: latitude display

Posted on 2000-04-06
3
164 Views
Last Modified: 2010-04-02
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.
0
Comment
Question by:skanade
  • 2
3 Comments
 
LVL 18

Accepted Solution

by:
deighton earned 100 total points
ID: 2689096
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
 
LVL 18

Expert Comment

by:deighton
ID: 2689929
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 Comment

by:skanade
ID: 2690535
Thanks!
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Need some help with listview limit text 20 112
C++ Language error 28 246
convert char array to number in c 5 86
show out valin of json for debugging in visaul c++ 1 41
Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question