Greetings

Further to the discussion here:, I have made a few modifications to the calculation provided by **jbante**. These modifications include:

- Getting the Cardinal directions (N,S,E,W) reporting corrctly for positive (N, E) cardinals and (S, W) for negative cardinals,
- Leading Zeroes on whole degrees for both Latitude and Longitude -to more closely comply with "correct" (perhaps more commonly used and familiar?) notation, and
- Limited the decimal precision of Minutes of arc to 5 places.

So far, so good.

My final stumbling block with this is to get Leading Zeroes in the whole minutes notation of the coordinates. For example, the Decimal Latitude coordinate -4.00699999183416 is correctly rounding to -4.00699999. After calculation, the result is displaying as: S04° .42'... which should be, with "correct" notation: S04° **00**.42'. I've tried adding a Right function, without success... I suspect it may be to do with *where* I am calling that function, but I can't make it work!

The calculation as it currently exists:

Let ( [

~original = LATITUDE ;

~negative = ~original < 0 ; // True (1) if value is negative

~positive = Abs ( ~original ) ;

~degrees = Div ( ~positive ; 1 ) ;

~minutes = Mod ( ~positive ; 1 ) * 60 ;

~decimal = ~degrees + ~minutes / 60 ;

~decimal = If ( ~negative ; 0 - ~decimal ; /* Else */ ~decimal )

] ;

If ( ~negative ; "S" ; "N")

& Right ( "00" & ~degrees ; 2 ) & "° "

& Round ( ~minutes ; 5 ) & "'"

)

Would appreciate any assistance available!

Regards

RS

I use a custom function to pad strings (see below). You could use this (either as a custom function, or incorporate it to you let statement) to add leading zeros

/* Pad ( _input ; _char ; _length ; _left_or_right )

Padds a string on a given length, left or right.

Not recursive.

Pad ( "James" ; "+-" ; 10 ; "Right" ) --> "James+-+-+"

Pad ( "45.52" ; "." ; 15 ; "Left" ) --> "..........45.52"

Substitute ( text ; searchString ; replaceString )

*/

Let ([

_str = Substitute ( ( 10 ^ _length ) - 1 ; 9 ; _char )

; _side = Case ( _left_or_right = "right" or _left_or_right = "r" or _left_or_right = "Right"; "R" ; "L" )

];

Case ( _side = "R"

; Left ( _input & _str ; _length ) ; Right ( _str & _input ; _length )

)

)

Message was edited by: deninger (modified the comment to reflect the actual pad direction, as I had changed it years ago to reflect how I though it should work)