I want to write the If statement below in a Google Sheet:
If today's date is greater than the payment deadline, then return the overdue payment amount. Otherwise, return 0.
I did this:
=if(F11<"=TODAY()",C11,0) + if(F12<"=TODAY()",C12,0) + if(F13<"=TODAY()",C13,0) + if(F14<"=TODAY()",C14,0) + if(F15<"=TODAY()",C15,0) + if(F16<"=TODAY()",C16,0) + if(F17<"=TODAY()",C17,0)
The values in column F are dates written the date format month/day/year. All of the dates in column F are greater than today's date.
The values in column C are dollar amounts with decimals.
First Attempt:
=if(F11<"=TODAY()",C11,0) + if(F12<"=TODAY()",C12,0) + if(F13<"=TODAY()",C13,0) + if(F14<"=TODAY()",C14,0) + if(F15<"=TODAY()",C15,0) + if(F16<"=TODAY()",C16,0) + if(F17<"=TODAY()",C17,0)
Second Attempt:
=if(F11<"TODAY()",C11,0) + if(F12<"TODAY()",C12,0) + if(F13<"TODAY()",C13,0) + if(F14<"TODAY()",C14,0) + if(F15<"TODAY()",C15,0) + if(F16<"TODAY()",C16,0) + if(F17<"TODAY()",C17,0)
Third Attempt:
=if(DATEVALUE(F11)<"TODAY()",C11,0) + if(DATEVALUE(F12)<"TODAY()",C12,0) + if(DATEVALUE(F13)<"TODAY()",C13,0) + if(DATEVALUE(F14)<"TODAY()",C14,0) + if(DATEVALUE(F15)<"TODAY()",C15,0) + if(DATEVALUE(F16)<"TODAY()",C16,0) + if(DATEVALUE(F16)<"TODAY()",C17,0)
I expect to get 0 overdue payments as all the payment deadlines are greater than today's day. Could you please help me?
your formula should be:
=IF(F11<TODAY(), C11, 0) +
IF(F12<TODAY(), C12, 0) +
IF(F13<TODAY(), C13, 0) +
IF(F14<TODAY(), C14, 0) +
IF(F15<TODAY(), C15, 0) +
IF(F16<TODAY(), C16, 0) +
IF(F17<TODAY(), C17, 0)
next level formula would be:
=ARRAYFORMULA(SUM(IF(F11:F17<TODAY(), C11:C17, 0)))
or shorter:
=SUMIF(F11:F17, "<"&TODAY(), C11:C17)
I am trying to make this statement applicable to some cells in my google spreadsheet :
if ((B29 - B36) > 0) {
(B29 - B36) * (D36 / 100) + F35 + F34 + F33
} else if ((B29 - B35) > 0) {
(B29 - B35) * (D35 / 100) + F34 + F33);
} else if (B29 - B34 > 0) {
(B29 - B34) * (D34 / 100) + F33);
} else {
0
}
I tried to make it with only IF, but the cells didn't like the syntax :
=IF((B29 - B36) > 0);((B29 - B36) * (D36 / 100) + F35 + F34 + F33);IF((B29 - B35) > 0);((B29 - B35) * (D35 / 100) + F34 + F33);IF((B29 - B34) > 0);((B29 - B34) * (D34 / 100) + F33);0
How can I achieve this?
correct syntax would be like this:
=IF(B29-B36 > 0; (B29-B36)*(D36/100)+F35+F34+F33;
IF(B29-B35 > 0; (B29-B35)*(D35/100)+F34+F33;
IF(B29-B34 > 0; (B29-B34)*(D34/100)+F33; 0)))
ho could I manipulate some Int adding them as minutes and sum them? the result should be in hours and minutes just like 1:15 or 6:30.
My playground gives 1.25 but I expected 1.15
struct standardDayOfWork {
var dailyHours : Double = 0
}
var dayToUse = standardDayOfWork()
enum hourFractions : Double {
case quarter = 15
case half = 30
case threeQuarter = 45
case hour = 60
}
dayToUse.dailyHours += hourFractions.half.rawValue
dayToUse.dailyHours += hourFractions.half.rawValue
dayToUse.dailyHours += hourFractions.quarter.rawValue
var total = dayToUse.dailyHours / 60 //1.25
Because in the decimal system a quarter is 0.25.
To get numeric 1.15 you could use this weird expression:
var total = Double(Int(dayToUse.dailyHours) / 60) + (dayToUse.dailyHours.truncatingRemainder(dividingBy: 60) / 100.0)
Or if you can live with a formatted "hh:mm" string I'd recommend
let formatter = DateComponentsFormatter()
formatter.allowedUnits = [.hour, .minute]
formatter.string(from: dayToUse.dailyHours * 60)
I am attempting to convert the first code snippet at:
Calculate distance between 2 GPS coordinates
// var R = 6371; // km
// var dLat = (lat2-lat1).toRad();
// var dLon = (lon2-lon1).toRad();
// var lat1 = lat1.toRad();
// var lat2 = lat2.toRad();
// var a = Math.sin(dLat/2) * Math.sin(dLat/2) +
// Math.sin(dLon/2) * Math.sin(dLon/2) * Math.cos(lat1) * Math.cos(lat2);
// var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
// var d = R * c;
(also shown below) for use in qt c++. It is used in a program that simulates gps flight inside of a radio control simulator. The GpsCalcLoop grabs gps latitude and longitude (in decimal format) once per second. These are fed into my converted code in hopes of getting a distance traveled during that one second of time. Speed would then be calculated.
I used the information at this page:
http://doc.qt.io/qt-4.8/qtcore-qmath-h.html
to convert the math functions. The output, however, is not what I expected. No matter what is input into lat2, lat1, lon2, and lon1 the results are always the same, '16777200.00'.
I am hoping that someone more familiar with qt c++ will be able to show me where I have gone wrong with the conversion. or point me to where I can find qt c++ code that is working.
I will add that I have attempted to use "#include "<"QGeoPositionInfo">" but get a 'No such file or directory' error when running the program.
void TelemetrySimulator::onGpsCalcLoop()
{
if(rungps)
{
ui -> valuetest1 -> setValue(flat);
ui -> valuetest2 -> setValue(flat2);
ui -> valuetest3 -> setValue(flon);
ui -> valuetest4 -> setValue(flon2);
ui -> valuetest5 -> setValue(flat-flat2);
ui -> valuetest6 -> setValue(flon-flon2);
flat2 = flat;
flon2 = flon;
//--https://stackoverflow.com/questions/365826 //calculate-distance-between-2-gps-coordinates--
// var R = 6371; // km
// var dLat = (lat2-lat1).toRad();
// var dLon = (lon2-lon1).toRad();
// var lat1 = lat1.toRad();
// var lat2 = lat2.toRad();
// var a = Math.sin(dLat/2) * Math.sin(dLat/2) +
// Math.sin(dLon/2) * Math.sin(dLon/2) * Math.cos(lat1) * Math.cos(lat2);
// var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
// var d = R * c;
//--------------my conversio to qt c++---------
//---converted to qt using this web page -> http://doc.qt.io/qt-4.8/qtcore-qmath-h.html----
double R, dLat, dLon, lat1, lat2, lon2, lon1, a, c, d;
lat2 = flat2;
lat1 = flat;
lon2 = flon2;
lon1 = flon;
R = 6371; // km
dLat = qAcos(lat2-lat1); //dLat = (lat2-lat1).toRad(); instead of qAcos could be qAsin, qAtan, qCos, qSin,
// qTan. All refer to Radials.
dLon = qAcos(lon2-lon1); //dLon = (lon2-lon1).toRad();
lat1 = qAcos(lat1); //lat1 = lat1.toRad();
lat2 = qAcos(lat2); //lat2 = lat2.toRad();
a = qSin(dLat/2) * qSin(dLat/2) + //Math.sin(dLat/2) * Math.sin(dLat/2) +
qSin(dLon/2) * qSin(dLon/2) * qCos(lat1) * qCos(lat2);//Math.sin(dLon/2) * Math.sin(dLon/2) * Math.cos(lat1) * Math.cos(lat2);
c = 2 * qAtan2(qSqrt(a), qSqrt(1-a)); //Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
d = R * c;
ui -> valuetest7 -> setValue(d);
}
}
Thanks to everyone for your great help! Here is the final code:
void MainWindow::onGpsCalcLoop()
{
//Get initial values from gps run loop-------
double lat2 = flat2;
double lat1 = flat;
double lon2 = flon2;
double lon1 = flon;
//GPS distance and speed calculation -------
double dLat = .01745329 * (lat2 - lat1);
double dLon = .01745329 * (lon2 - lon1);
lat1 = .01745329 * lat1;
lat2 = .01745329 * lat2;
double a = qSin(dLat/2) * qSin(dLat/2) +
qSin(dLon/2) * qSin(dLon/2) * qCos(lat1) * qCos(lat2);
double c = 2 * qAtan2(qSqrt(a), qSqrt(1-a));
double d = 3975 * c;
//Distance calculation done. Next is total distance and speed------
td = td + d;
if (d > .1)
{
d = 0;
td = 0;
}
if (ui -> metric -> isChecked())
{
ui -> valuetest1 -> setValue(td * 1.6);
ui -> valuetest2 -> setValue((d * 3600) * 1.6);
}
else
{
ui -> valuetest1 -> setValue(td);
ui -> valuetest2 -> setValue(d * 3600);
}
flat2 = flat;
flon2 = flon;
}
I used .01745329*(whatever) instead of qDegreesToRadians(whatever) just to keep things as simple as possible.
Again, thanks to all for your help!
I am trying to translate some Pascal code into C++ code. I am stuck trying to figure out how to translate this portion.
Function ThetaG_JD(jd : double) : double;
var
UT,TU,GMST : double;
begin
**UT := Frac(jd + 0.5);**
jd := jd - UT;
TU := (jd - 2451545.0)/36525;
GMST := 24110.54841 + TU * (8640184.812866 + TU * (0.093104 - TU * 6.2E-6));
**GMST := Modulus(GMST + 86400.0*1.00273790934*UT,86400.0);**
ThetaG_JD := twopi * GMST/86400.0;
end; {Function ThetaG_JD}
I am particularly having trouble with the two lines I made bold. How can I translate this to c++? Thank you so much.
In C++ the equivalent functions would be:
fmod to get a floating point modulus
modf to break a floating point item into its fraction and integral parts (equivalent of Frac).
If you want to calculate Julian Day, Greenwich Mean Sidereal Time and Local Mean Sidereal Time, maybe the below can help you - written in PowerShell:
<#
.Synopsis
Astronomy calculations
.Description
Some helper functions to calculate:
- Julian Day,
- Greenwich Mean Sidereal time,
- Local Mean Sidereal Time.
#>
cls
# https://en.wikipedia.org/wiki/Julian_day#Julian_day_number_calculation
function Get-JulianDay
{
param ( [System.DateTime]$dt )
$year = $dt.Year
$month = $dt.Month
$day = $dt.Day
$hour = $dt.Hour
$minute = $dt.Minute
$second = $dt.Second
$a = [System.Math]::Floor((14 - $month) / 12)
$y = $year + 4800 - $a
$m = $month + 12 * $a - 3
$JDN = $day + [System.Math]::Floor((153 * $m + 2) / 5) + 365 * $y + [System.Math]::Floor($y / 4) - [System.Math]::Floor($y / 100) + [System.Math]::Floor($y / 400) - 32045
$JD = $JDN + ($hour - 12) / 24 + $minute / 1440 + $second / 86400
return ($JD)
}
# https://en.wikipedia.org/wiki/Sidereal_time#Definition
# http://aa.usno.navy.mil/faq/docs/GAST.php
function Get-GMST
{
param ( [double]$JD )
$D = $JD - 2451545.0
$GMST = 18.697374558 + 24.06570982441908 * $D
return ($GMST % 24)
}
function Get-LMST
{
param ( [double]$gmst, [double]$longitude )
return ( $gmst + $longitude / 15.0 )
}
# Test above functions
$current = (Get-Date).ToUniversalTime()
$jd = Get-JulianDay -dt $current
$gmst = Get-GMST -JD $jd
$longitude = 17.668487800
$lmst = Get-LMST -gmst $gmst -longitude $longitude
$lst = [timespan]::FromHours($lmst).ToString()
Write-Host "Local mean sidereal time: $lst"