I'm trying to create a decimal formatting formula on my summary fields. The values in the database could have 0, 1, or 2 decimal places. I've started with this:
If (CurrentFieldValue mod 1 = 0) Then
0
Else If (CurrentFieldValue mod .1 = 0) Then
1
Else
2
On a simple single data field, this works and displays the value with 0, 1, or 2 decimal places based on the data coming from my database. The same formula doesn't work for a summary field on my reports with group data. Any ideas?
Edit: Since I don't know how to format code in a comment, I'll address the suggestion of using a formula here:
Didn't work. Formula:
Sum ({myTable.dataValue}, {myTable.groupField})
then I used:
If ({#formula} mod 1 = 0) Then
0
Else If ({#formula} mod .1 = 0) Then
1
Else
2
And I still got whole numbers for everything. My rounding is set to .01 with no formula. Do I need a formula for rounding too? I still don't understand why this works on individual values but not for group summaries.
OK- it turns out this is due to our lack of understanding of the mod function :)
Everything mod 1 actually returns 0. This is the formula you need to use:
if {ER100_ACCT_ORDER.ER100_ORD_TOT} * 100 mod 100 = 0 then
0
else if {ER100_ACCT_ORDER.ER100_ORD_TOT} * 100 mod 10 = 0 then
1
else
2
:)
How about just creating a formula field instead of using the built-in summary field:
sum({mytable.myfield})
Then you can use your conditional formatting:
If ({#formula} mod 1 = 0) Then
0
Else If ({#formula} mod .1 = 0) Then
1
Else
2
Related
I understand the whole code and
I just want to know why there has to be a -1 at the end of the range function.
I've been checking it out with pythontutor but I can't make it out.
#Given 2 strings, a and b, return the number of the positions where they
#contain the same length 2 substring. So "xxcaazz" and "xxbaaz" yields 3,
#since the "xx", "aa", and "az" substrings appear in the same place in
#both strings.
def string_match(a, b):
shorter = min(len(a), len(b))
count = 0
for i in range(shorter -1): #<<<<<<<<< This is -1 I don't understand.
a_sub = a[i:i+2]
b_sub = b[i:i+2]
if a_sub == b_sub:
count = count + 1
return count
string_match('xxcaazz', 'xxbaaz')
string_match('abc', 'abc')
string_match('abc', 'axc')
I expect to understand why there has to be a -1 at the end of the range function. I will appreciate your help and explanation!
The value indices of the for loop are counted since 0 so the final value actually would be the (size -1)
I have the following 3 examples of case expressions in postgres, which I would expect to evaluate in the same way. However the first and the third give ERROR: invalid input syntax for integer: "2017,7". The second one seems to be ok. Why is the difference?
Postgres documentation states
"A CASE expression does not evaluate any subexpressions that are not
needed to determine the result."
select case when 0 = 0 then 1 < 2
when 0 = 2 then ('2017.7')::bigint > 2000
end
(DB Fiddle)
select case when 0 = 0 then 1 < 2
when 0 = 2 then 2000 = ('2017.7'||'')::bigint
end
(DB Fiddle)
select case when (array[1,2])[1] =1 then 1 < 2
when (array[1,2])[1] = 2 then 2000 = ('2017.7'||'')::bigint
end
(DB Fiddle)
I have a table in MATLAB with attributes in the first three columns and data from the fourth column onwards. I was trying to sort the entire table based on the first three columns. However, one of the columns (Column C) contains months ('January', 'February' ...etc). The sortrows function would only let me choose 'ascend' or 'descend' but not a custom option to sort by month. Any help would be greatly appreciated. Below is the code I used.
sortrows(Table, {'Column A','Column B','Column C'} , {'ascend' , 'ascend' , '???' } )
As #AnonSubmitter85 suggested, the best thing you can do is to convert your month names to numeric values from 1 (January) to 12 (December) as follows:
c = {
7 1 'February';
1 0 'April';
2 1 'December';
2 1 'January';
5 1 'January';
};
t = cell2table(c,'VariableNames',{'ColumnA' 'ColumnB' 'ColumnC'});
t.ColumnC = month(datenum(t.ColumnC,'mmmm'));
This will facilitate the access to a standard sorting criterion for your ColumnC too (in this example, ascending):
t = sortrows(t,{'ColumnA' 'ColumnB' 'ColumnC'},{'ascend', 'ascend', 'ascend'});
If, for any reason that is unknown to us, you are forced to keep your months as literals, you can use a workaround that consists in sorting a clone of the table using the approach described above, and then applying to it the resulting indices:
c = {
7 1 'February';
1 0 'April';
2 1 'December';
2 1 'January';
5 1 'January';
};
t_original = cell2table(c,'VariableNames',{'ColumnA' 'ColumnB' 'ColumnC'});
t_clone = t_original;
t_clone.ColumnC = month(datenum(t_clone.ColumnC,'mmmm'));
[~,idx] = sortrows(t_clone,{'ColumnA' 'ColumnB' 'ColumnC'},{'ascend', 'ascend', 'ascend'});
t_original = t_original(idx,:);
I'm quite new to Matlab so excuse me for the basic question.
I need to make a for-loop that repeats it's self 384 times.
So :
for i=1:384
I now need the for loop to check if 2 certain variables have the value 1 through 10, and then let them store this in a new variable with that value.
So:
if x==1
somevariable = 1
elseif x== 2
saomevariable = 2
..
..
..
elseif y = 1
someothervariable = 1
etc etc.
Is there a way to write this more efficient?
Thank you!
The first think you can do is:
if(x >= 1 && x <= 10)
somevariable=x;
end
if(y >= 1 && y <= 10)
someohtervariable=y;
end
If you could post more information about "x" and "y", perhaps your script can be further "improved".
Hope this helps.
I want to implement the following formula in MATLAB, where u_i^(k) means the i,k element. However, I get different results from the ones I compute by hand... I believe that something is wrong with my MATLAB code. For instance,
I should get:
L_ii =
0.1022 0 0
0 0.1657 0
0 0 2.7321
U_ij =
0.7514 0.3104 0.5823
-0.6513 0.4901 0.5793
-0.1055 -0.8145 0.5704
1,1=1-(0.1022*(+0.7514)^2+0.1657*(+0.3104)^2+2.7321*(+0.5823)^2)=-0.000049
2,2=1-(0.1022*(-0.6513)^2+0.1657*(+0.4901)^2+2.7321*(+0.5793)^2)=-0.000015
3,3=1-(0.1022*(-0.1055)^2+0.1657*(-0.8145)^2+2.7321*(+0.5704)^2)=+0.000030
Any ideas??? Please, help me fix Epsilon first (it might not need to move on Rho. Let's fix Epsilon first...)
EDIT: Here is a sample code:
E_squared_ii = ONES_j - diag(L_ii)' * (U_ij'.^ 2)
And here is the wrong result I get at the moment:
E_squared_ii =
1.0e-15 *
0.444089209850063 0.333066907387547 -0.222044604925031
If I use your values and code, I get the expected result:
>> L_ii
L_ii =
0.1022 0 0
0 0.1657 0
0 0 2.7321
>> U_ij
U_ij =
0.7514 0.3104 0.5823
-0.6513 0.4901 0.5793
-0.1055 -0.8145 0.5704
>> ONES_j
ONES_j =
1 1 1
>> E_squared_ii = ONES_j - diag(L_ii)' * (U_ij'.^ 2)
E_squared_ii =
1.0e-04 *
-0.4935 -0.1451 0.2985
Presumably this means that something isn't the value you think it is...