by 2b3a51 · 4y ago · 0 comments
=CONCATENATE(
IF(A1<0;"-";"+");
TEXT(INT(ABS(A1));"00") ;"d";
IF((ABS(A1) - INT(ABS(A1)) - INT( (ABS(A1) - INT(ABS(A1)))*60 )/60) * 3600 > 59.5;
TEXT(INT((ABS(A1) - INT(ABS(A1)))*60)+1;"00");
TEXT(INT((ABS(A1) - INT(ABS(A1)))*60);"00")
);"m";
IF((ABS(A1) - INT(ABS(A1)) - INT( (ABS(A1) - INT(ABS(A1)))*60 )/60) * 3600 > 59.5;
TEXT(0;"00");
TEXT(ROUND( (ABS(A1)-INT(ABS(A1))-INT((ABS(A1)- INT(ABS(A1)))*60)/60)*3600;0 );"00")
);"s"
)
...which should take a value in cell A1 that is in the range [0,360) and return the value in angle notation (degrees, minutes and seconds). I especially wanted this function all in one cell to save loads of helper cells (the spreadsheet calculates the position of the moon, sun, planets and a physical ephemeris for each planet so a lot of angles to display).It is a pain to apply, I use a text editor to search and replace the cell reference for each angle. I'd settle for the formula bar display of the formula not reformatting the line breaks.
I'm not sure this works with LibreOffice though. Probably not.
I rapidly tried and I get something a bit shorter (about half the length), but my rounding ends up with imperfect precision and sometimes I get 10m60s rather than 11m0s due to it. Appropriate rounding at the appropriate points would fix that.
I assume you have tried the '$' signs to see if they will help?
'$' signs for A1? I'd still need to search and replace for A1 each time I needed to convert an angle in a different cell but I take your point that I could move the output around more easily. Speed does not seem to be an issue (the rest of the spreadsheet has calls to trig functions by the score)
e.g. $A1 locks the column, A$1 the row and $A$1 both
Can be pretty helpful if you put a constant somewhere.
As a concrete example (just in case I've mis-understood the situation), I have the right ascension, declination and phase angle of Venus as decimal angles in cells G80, H80 and M80 and I want the output strings in cells F3, G3 and H3. I still need to search and replace the A1 cell reference in my original post for each of the formulas.
As the poster a couple levels above pointed out I could do this as a user defined function in VBA, but I wanted my daft spreadsheet to work on Libre/Open office and on Google sheets with little or no modification. Hence the chain of if statements and round() functions.
I can't imagine how much time this one thing would have saved over my last 40 years of spreadsheeting.