I would like to convert coordinates from degrees minutes and seconds to decimal degrees in Google Sheets.
For example:
58⁰ 09' 0.5"N = 58 + 9/60 + 0.5/3600 = 58.1501389
In Google Spreadsheets there are functions like =left(E2,2)+(right(E2,7)/60).
But is there a way to pick numbers based on the location between sign marks (degree ⁰, minute ') ?
For example how to find numbers between degree sign ⁰ and minute sign '
Then divide those numbers by 60?
Given some coordinates in the exact DMS format you've stated in A1, the following formula in B1 gives the decimal form:
=ArrayFormula(sum(split(A1,"⁰'"")N")/{1,60,3600}))
N.B. when I copy a single " character into the SPLIT delimiter argument, Sheets automatically converts it to "") for some reason. It doesn't affect the split result here though.
Related
I have seen a similar question here, but that answer did not to the job for me yet. We have a Google Sheets doc with 46 adresses, and converted longitude and latitude from that location.
Now we would like to be able to give in a location, from which we also get the longitude and latitude and for which we find the closest address based on the coördinates in the list.
Our document is here:
https://docs.google.com/spreadsheets/d/1fKBGbRlOX6gw77Nk0S_9ZmsJ-fefM4mA_Ys-Mu-QHIA/edit?usp=sharing
In this file the addresses are shown in Column A, the longitude in column B and the latitude in column C. In Column E we will enter the location and in column F and G the longitude and latitude will be shown. Now in column H it should show the nearest location from the list in Column A.
We have tried:
ZOEKEN(1;1/INTERVAL(0;SIN((RADIALEN(B$2:B$47-F2))/2)^2+SIN((RADIALEN(C$2:C$47-G2))/2)^2*COS(RADIALEN(B$2:B$47))*COS(RADIALEN(G2)));A$2:A$47)
But the location it gives is not the closest upon checking in Google Maps.
Anyone able to help?
To get the real driving or commuting distances between two addresses, use the GoogleMapsDistance custom function. Note that a driving distance is different from a bee line distance. Your existing formula appears to calculate the latter:
=LOOKUP(1;1/FREQUENCY(0;SIN((RADIANS(B$2:B$47-F2))/2)^2+SIN((RADIANS(C$2:C$47-G2))/2)^2*COS(RADIANS(B$2:B$47))*COS(RADIANS(G2)));A$2:A$47)
The formula seems overly complex. When you are dealing with distances of max a couple hundred kilometers, you can use the Pythagorean theorem instead:
distance² = (startLat - endLat)² + (startLong - endLong)²
A trickier problem is that the custom function you are using does not return numeric latitudes and longitudes. It returns text strings that use period as the decimal mark. Your spreadsheet's locale does not use periods but commas as decimal mark. You should replace those periods with commas with substitute(), like this:
=arrayformula(
lambda(
addressStart; latStart; longStart; latEnd; longEnd;
map(
latEnd; longEnd;
lambda(
latThis; longThis;
if(
latThis * longThis;
sortn(
{ addressStart \ sqrt( (latStart - latThis) ^ 2 + (longStart - longThis) ^ 2 ) };
1; 0; 2; true
);
iferror(1/0)
)
)
)
)(
A2:A;
substitute(B2:B; "."; ",");
substitute(C2:C; "."; ",");
substitute(F2:F10; "."; ",");
substitute(G2:G10; "."; ",")
)
)
See your sample spreadsheet.
I am trying to record the time it takes for a number of things to occur, and can't seem to get Google Sheets to understand my input. I want to be able to type something like "26:30" into a cell, and have the spreadsheet understand that this means 26 minutes and 30 seconds, and then be able to use that number in formulas, e.g. to return the shortest of a series of times, or the difference between two times.
Also, the vast majority of the numbers I type in will be under an hour, so I don't want to have to type in something like "0:26:30" every time, just for it to understand that I mean 26 minutes, not 26 hours. However for the rare occasions where something is longer than an hour, I want to be able to be able to type something like "1:10:23" and not "70:23".
If possible, I would rather achieve this through directly formatting the cell I type the time into, rather than enter it in one format and have it converted in a separate cell via a formula.
Is there a way to do this that meets all of these goals?
google sheets is not designed in such a way. if you want to type in 26:30 then the best course of action is as follows:
convert cells to Plain Text, type in your duration, and account for your rules within formulae. to convert a text string into a value for the sake of calculation you can use the following principle
=ARRAYFORMULA(IFERROR(IF(REGEXMATCH(A1:A, ":\d+:"), A1:A*1, ("0:"&A1:A)*1)))
few examples:
=ARRAYFORMULA(TEXT(AVERAGE(IF(REGEXMATCH(A1:A2, ":\d+:"),
A1:A2*1, ("0:"&A1:A2)*1)), "[m]:ss"))
=ARRAYFORMULA(TEXT(SUM(IF(REGEXMATCH(A1:A2, ":\d+:"),
A1:A2*1, ("0:"&A1:A2)*1)), "[h]:mm:ss"))
=ARRAYFORMULA(TEXT(IF(REGEXMATCH(A2, ":\d+:"), A2*1, ("0:"&A2)*1)-
IF(REGEXMATCH(A1, ":\d+:"), A1*1, ("0:"&A1)*1), "[m]:ss"))
At this point in time there doesn't seem to be a way to directly format a cell such that Google Sheets recognises it as MM:SS instead of HH:MM, so I've had to go with formulas instead. Sharing the solution I used below.
I set it up so that the user entered the time into cell A1 in the form MM:SS or H:MM:SS and I formatted this cell as plain text, then had a second cell formatted as 'time duration' where it converted the input of A1 using the following formula:
=time(left(A1,if(len(A1)<6,"",len(A1)-6)),right(left(A1,len(A1)-3),2),right(A1,2))
To break this down:
It starts by assuming the contents of A1 is a text string with 5 or more characters in the form MM:SS or H:MM:SS or HH:MM:SS. It does not include any sort of error handling to check this is true.
The time(X,Y,Z) part of the formula converts different inputs into hours, minutes and seconds, respectively, and produces a number in the format HH:MM:SS, which is recognised as a time, and can therefore be used in formulas. Note that the cell has to be formatted as 'time duration' to display correctly.
In the above, Z is right(A1,2) which extracts the last two characters of A1, i.e. the SS part of the input. These end up as seconds.
Likewise, Y is right(left(A1,len(A1)-3),2) which extracts the 4th and 5th characters from the right of the text string of A1, i.e. the MM part of the input, after the :. This number is then recognised as minutes.
Finally, X is left(A1,if(len(A1)<6,"",len(A1)-6)), which basically says "if A1 is less than 6 characters then it must not have hours, so leave blank, otherwise extract out all characters except the last 6", i.e. the HH part of the input, if it exists. This number (which may or may not be 0) is then recognised as hours.
In Google Sheets I'm trying to format numbers to have format "0.##" - so that integer be like integer (12 be exactly 12), decimals be like decimals with no trailing zeroes (12.30 be 12.3 and 12.4321 be 12.43), but in reality
for 12 I've got 12. with this annoying decimal point and see NO WAY to get rid of it.
The same time if I choose Format -> Number -> Automatic, I've got calculated numbers be like 131.3666667 which is not my desired format.
In LibreOffice using format "0.##" removes unnecessary decimal point, but Google Sheets don't. If you know how to do it, please share your knowledge. Googling doesn't help much.
Thank you in advance!
Number format 0.## works well with Google Apps Script. It does not leave dot to numbers that has no decimals.
The code below will apply number formatting to the whole Sheet.
Try this:
function formatColumn() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName("Sheet1");
var range = sheet.getRange(1, 1, sheet.getMaxRows(), sheet.getMaxColumns());
range.setNumberFormat("0.##");
}
*Note:
You can change the range to column specific by changing the value of getRange(). Example: sheet.getRange(A1:A).
If you choose to format the whole sheet, you only need to run the script once to apply the format.
Output:
Before:
After:
Since we set the format to the whole sheet, It will automatically format any inputted numbers.
Reference:
Google Apps Script
Class Range
Range.setNumberFormat(numberFormat)
hi i found the Solution :
For Example let us say that you have the number 100 in the cell A1 ,
and you have the Number 99.9 in the cell B1 .
let us say you want to get the sum of them without having the.9 .
click on the cell that you want to add the sum on it :
let us say it is the cell C1 click on it then add =INT //(MUST BE CAPITAL) :
for example :
= INT(A1 + B1)
then hit Enter .
now the value of the sum is :
199
If you don't use the result of these cells for further calculation (or if you do use, but don't mind losing some precision), you can surround your current formula with Round(..., 2) and leave the format as automatic.
Some examples of what original numbers will appear as:
1.004 -> 1
1.006 -> 1.01
1.096 -> 1.1
I have a zap # Zapier which automatically imports my Strava activity to Google Sheets. This works fine, but it inputs everything as text. I want to be able to calculate my running (accumulated) average pace, but it is not possible with the data as is. So, do any of you have any formulaes for converting the info in column G to proper google sheets time format so that I can use it for calculations?
Here is a link to the data: https://docs.google.com/spreadsheets/d/1UD25--vrVgVp0AuhLFi7CGWFIo-GHeLfD_n8WqDbNrE/edit?usp=sharing
Try this formula in any blank column on row 2.
=(value(left(G2;len(G2)-3)) + value(right(G2;2))/60)/60/24
This parses the time value, eg 2:34, in column G, extracting the minutes from in front of the colon, and the seconds from after the colon, converts them from text to numbers, adds them together, and divides by 60 to get hours, and by 24 to get fractions of a day. Is this what you want?
For a formula that will do the whole column, place the following in row 1 of a blank column, and format the column for Time:
={"Time";arrayformula((value(left(G2:G;len(G2:G)-3)) + value(right(G2:G;2))/60)/60/24)}
Let me know if you need something else.
I need to sum all the numbers in a string, in the string there won't be any letters only numbers. The cell contains 112121.
I tried using SUM and CASE with the QUERY Function, but CASE is not supported.
Example: 1121 = 5.
=SUMPRODUCT(REGEXEXTRACT(TO_TEXT(A1), REPT("(.)", LEN(A1))))
=INDEX(QUERY(,"SELECT "®EXREPLACE(TO_TEXT(A1),"\B","+")),2)
Convert A1 TO_TEXT
Change All non Boundary to + using REGEXREPLACE
Query's Select can accept math strings and perform calculations
INDEX to remove headers