A formula is a mathematical equation or expression that performs various operations on variables to produce an outcome.
Questions tagged [formula]
6145 questions
265
votes
26 answers
Too many 'if' statements?
The following code does work how I need it to, but it's ugly, excessive or a number of other things. I've looked at formulas and attempted to write a few solutions, but I end up with a similar amount of statements.
Is there a type of math formula…

TomFirth
- 2,334
- 4
- 20
- 31
220
votes
16 answers
Base64 length calculation?
After reading the base64 wiki ...
I'm trying to figure out how's the formula working :
Given a string with length of n , the base64 length will be
Which is : 4*Math.Ceiling(((double)s.Length/3)))
I already know that base64 length must be %4==0…

Royi Namir
- 144,742
- 138
- 468
- 792
161
votes
21 answers
Formula px to dp, dp to px android
I am trying to calculate a variable amount of pixels to density independent pixels and vice-versa.
This formula (px to dp): dp = (int)(px / (displayMetrics.densityDpi / 160)); does not work on small devices because it is divided by zero.
This is…

Bram
- 4,533
- 6
- 29
- 41
142
votes
9 answers
Convert light frequency to RGB?
Does anyone know of any formula for converting a light frequency to an RGB value?

Shaul Behr
- 36,951
- 69
- 249
- 387
92
votes
5 answers
Formula with dynamic number of variables
Suppose, there is some data.frame foo_data_frame and one wants to find regression of the target column Y by some others columns. For that purpose usualy some formula and model are used. For example:
linear_model <- lm(Y ~ FACTOR_NAME_1 +…

Max
- 4,792
- 4
- 29
- 32
90
votes
9 answers
How to turn a string formula into a "real" formula?
I have 0,4*A1 in a cell (as a string). How can convert this "string formula" into a real formula and calculate its value, in another cell?

Cloaky
- 1,065
- 2
- 10
- 11
83
votes
11 answers
Calculate percentage saved between two numbers?
I have two numbers, the first, is the original price, the second, is the discounted price.
I need to work out what percentage a user saves if they purchase at the second price.
example
25, 10 = 60%
365, 165 = 55%
What I dont know is the formula…

Hailwood
- 89,623
- 107
- 270
- 423
81
votes
2 answers
Dynamically evaluate an expression from a formula in Pandas
I would like to perform arithmetic on one or more dataframes columns using pd.eval. Specifically, I would like to port the following code that evaluates a formula:
x = 5
df2['D'] = df1['A'] + (df1['B'] * x)
...to code using pd.eval. The reason for…

cs95
- 379,657
- 97
- 704
- 746
68
votes
16 answers
How to extract URL from Link in Google Sheets using a formula?
I have copied from a website a series of hyperlinks and pasted them in a google sheet. The values show up as linked text, not hyperlink formulas, and are still linked correctly. For each row, I'm trying to extract the URL ONLY (not the friendly…

iamtoc
- 1,569
- 4
- 17
- 24
68
votes
6 answers
How to format a duration as HH:mm?
In the new Google sheets there's a way of formatting a number as a duration. Format -> Number -> Duration.
1 is formatted as 24:00:00
1.2 is formatted as 28:48:00
1.5 is formatted as 36:00:00
0.03125 is formatted as 0:45:00.
I don't need the…

Christiaan Westerbeek
- 10,619
- 13
- 64
- 89
66
votes
3 answers
Excel: Scalar product of two ranges
I am trying to find a proper way to calculate the scalar product of two ranges. For instance, the product of A1:A3 and B1:B3 would be A1*B1 + A2*B2 + A3*B3. Is there a good way to do this? Hardcoding this calculation is quite a tedious thing to do…

Lee White
- 3,649
- 8
- 37
- 62
63
votes
1 answer
In R formulas, why do I have to use the I() function on power terms, like y ~ I(x^3)
I'm trying to get my head around the use of the tilde operator, and associated functions. My 1st question is why does I() need to be used to specify arithmetic operators? For example, these 2 plots generate different results (the former having a…

ChrisW
- 4,970
- 7
- 55
- 92
58
votes
10 answers
How to utilize date add function in Google spreadsheet?
I believe the issue I am having now should be much easier in MS Excel. However, since my company uses Google Spreadsheet so I have to figure out a way.
Basically, I have a cell that contains a date value like "12/19/11", and I have another cell…

Kevin
- 6,711
- 16
- 60
- 107
54
votes
8 answers
Method for evaluating math expressions in Java
In one of my projects I want to add a feature where the user can provide in a formula, for example
sin (x + pi)/2 + 1
which I use in my Java app
/**
* The formula provided by the user
*/
private String formula; // = "sin (x + pi)/2 + 1"
/*
*…

Ethan Leroy
- 15,804
- 9
- 41
- 63
53
votes
2 answers
How to use reference variables by character string in a formula?
In the minimal example below, I am trying to use the values of a character string vars in a regression formula. However, I am only able to pass the string of variable names ("v2+v3+v4") to the formula, not the real meaning of this string (e.g., "v2"…

Eric Green
- 7,385
- 11
- 56
- 102