I have a particular application that needs to calculate something very specific, and while I excel at logic, math has always been my weak spot.
Given a number, say -20, it needs to apply a calculation of a 100 base (that is, the base is 100, not 0. not to be confused with base 100 which would be something else totally).
In other words, the math works like this ..., 105, 104, 103, 102, 101, 100, -101, -102, -103, -104, -105, ...
Then I need to do the math based on this 100 base figure.
So, for example:
-140 - 20 = 120
-120 - 20 = 100
-115 - 20 = -105
-110 - 20 = -110
-105 - 20 = -115
100 - 20 = -120
120 - 20 = -140
If it helps, the problem is related to sports odds. In theory, this refers to money (risk $1.40 to win $1.00 on one side, risk $1.00 to win $1.20 on the other, the .20 difference is what casinos call "the juice" or their cut of moving money back and forth.) However, the program is not dealing with real money, it's more of a simulator.
My current formula works like this:
decimal CalculateSides(decimal side, decimal vig)
{
decimal newSide = side - vig;
newSide = -(newSide < 0) ? newSide + 100 : newSide - 100;
return (newSide < 0) ? newSide + 100 : newSide - 100;
}
While this formula works, I'm not very happy with the conditional +/-, but this is basically the only formula that works for me.
Can anyone suggest a way to improve this? Preferably without conditions of +/-?
EDIT:
When I asked the question, I knew one possible answer was "It's probably best the way you're doing it", and that seems to be the consensus.