LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Convert Latitude & Longitude string to double

Hi,

I would like to ask if anyone know how to convert Latitude & Longitude string to double? I have the Latitude & Longitude string like this: 36°55.7086'S & 174°48.4443'E
I need to seperate the Degree & Minutes like this:

36°55.7086'S -> 36 & 55.7086
&
174°48.4443'E -> 174 & 48.4443.

I used "Match Pattern.vi" to separate the string first.Then, use "Fract/Exp String To Number.vi". I also wired FALSE to "use system decimal point" & wired a 4 decimal double constant to "default" for the "Fract/Exp String To Number.vi". But the double interger came out with only two digits of precision like this:

36°55.7086'S -> 36 & 55.71
&
174°48.4443'E -> 174 & 48.44.


Can anyone tell me how to get four digits of precision for the minute?
Many thanks.
0 Kudos
Message 1 of 4
(4,025 Views)
Hi!

In LabWindows you can use a standard C function, strtod( ) , which convert a string to a double value.

Of course you need to use this function iteratively, not once for all the whole latitude expression.

Hope it helps.
0 Kudos
Message 2 of 4
(4,008 Views)
Hello Chaw,

The problem you are experiencing is most likely due to the fact that you have the digits of precision for your output numeric control set to 2 or the significant digits set to 4. In order to change this, right click on your output numeric control, select 'Format and Precision'. On the resulting dialog window, set your significant digits or digits of precision accordingly.

Thanks.
0 Kudos
Message 3 of 4
(3,980 Views)
I'm not sure to understand if you use CVI ou LV because you talk about "Match Pattern.vi"
Anyway, assuming you use CVI does the code below works for you ?

#include <formatio.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>

int main (int argc, char *argv[]) {

char Coordinate[256] = "174°48.4443'E"; //36°55.7086'S 174°48.4443'E
int Degree, Index=0;
double Minutes=0.0;

Degree = strtol (Coordinate, NULL, 10);
Index = FindPattern (Coordinate, Index, strlen(Coordinate), "°", 0, 0);
Minutes = strtod(&Coordinate[Index+1], NULL);
printf("Coordinate are : %d°%f\n", Degree, Minutes);
getchar();
return EXIT_SUCCESS;
}
Regards, Philippe proud to be using LabWindows since version 1.2
// --------------------------------------------------------------------------------------------
0 Kudos
Message 4 of 4
(3,974 Views)