Razor: Display procentage - razor

I thought there would be an easy solution but I didnt succeed in finding anything that worked!
var squatPro = sumTotalSquatWeight/sumTotalVolume;
It's basically just this line, I don't know how to make it to decimal, since the result now is just 0 when the numbers are 9120/14895 = 0,61.
Adding * 100 at the end of the code gave 0 as well so that wasn't a solution!
(I'm not using MVC)

You may need to cast the numerator to a decimal:
var squatPro = (decimal)sumTotalSquatWeight / sumTotalVolume;
And if you want to round to 2 decimal places you can use something like this:
#squatPro.ToString("0.##")
Or if you need it as a percentage you can use this:
#(string.Format("{0:P}", squatPro))

Related

Split number into expression

I have this expression:
=IIF(ISNOTHING(code.dividir((Sum(Fields!PPMS_PPM.Value,"DS_DataPPMsDosAniosAnterior")
* 1000000),Sum(Fields!PPMBSC_VentasPPM.Value,"DS_DataPPMsDosAniosAnterior"))),0,
code.dividir((Sum(Fields!PPMS_PPM.Value,"DS_DataPPMsDosAniosAnterior") * 1000000),
Sum(Fields!PPMBSC_VentasPPM.Value,"DS_DataPPMsDosAniosAnterior")))
Result of that is a number like: 32.3637282716252, how can I do to get only 32 plus 2 decimal numbers like 32.36 Regards
Pepe.. I feel these questions are pretty simple to solve if you just google it.. instead of asking such questions here..
but here is how it can be done anyway..
Right click on the text box that has this expression, properties -> formatting -> Number and then choose 2 decimal places. Done.

onkeyup regex for validating numbers

I have below function which is used onkeyup for an input field. I want to allow users to enter numbers like 1 or -1 i.e positive or negative integers(no decimals) only. The regex i have used doesn't allow negative sign in the beginning. Tried different things and also looked up other questions but couldn't come with the correct one. Is there a better way to do it? Any help is much appreciated
function onlynumbers ()
{var text1 = document.getElementById("box1");
var numregex = /[^0-9]/gi
if (numregex.test(text1.value))
{
text1.value=text1.value.replace(numregex,"");
}
}
You can use this one that matches the hyphen only when it isn't at the start of the string:
var numregex = /[^0-9-]|(?!^)-/g;
This regex will allow for whole numbers and negative whole numbers!
^-?[0-9]\d*$

Change a public var at runtime in as3? (flixel)

I'm trying to create a guessing game that has the user clicking on different colored boxes to see which one is correct. I have a public var that dictates which color(later image) to use. The code is this in my update:
if (FlxG.mouse.justPressed())
{
block2.distributionp = Math.random() * 2;
block2.colorArray = block2.distributionp;
block2.colorUnit = block2.colorArray;
}
(colorUnit and colorArray both equal distributionp, which is a ranom of 2 in the class file)
When I run this code, the change does occur, but it only seems to switch out once. The other times it's ignored. How can I get this to continuously switch out a random number that I can use later?
Thanks in advance!
Math.random() * 2 Returns a Number ranging from 0.000000000000 to 2.00000000, this includes numbers like 0.123456789 and 1.99999999 (Not sure exactly what decimal place it goes to but just saying it doesn't only return integers 0, 1 and 2). I'm not sure but I think you're problem lies in the range, so if you want a better range use this code.
MIN_VALUE * Math.random() + (MAX_VALUE - MIN_VALUE);
If you would like to only get integers you can use either Math.ceil() or Math.floor() like so :
Math.ceil(MIN_VALUE * Math.random() + (MAX_VALUE - MIN_VALUE));
I'm sorry if this does not help you but let me know if it doesn't and I will continue to try and help.
The value I'm getting is whole integers between 0 and 2. What I'm trying to do, is change the vaue for each time I click. I'm not sure what occurs. Perhaps I shouldn't have asked now. I'll ask later when I have more info. Sorry.

How can I define a abstract odd function in mathematica?

How can I define a abstract odd function, say f[x].
Whenever f[x]+f[-x] appears, mathematica simplifies it to zero.
This can be done easily using upvalues
f[x_] + f[y_] /; x == -y ^:= 0
Normally Mathematica would try to assign the above rule to Plus, which of course does not work since that's protected. By using ^:= instead of := you can assign the rule to f. A quick check yields:
In[2]:= f[3]+f[-3]
Out[2]:= 0
Edit: This, however, only works for Plus. It's probably better to use something more general, like:
f[x_?Negative] := -f[-x]
Now this also works with things like
In[4]:= -f[3] - f[-3]
Out[4]:= 0
If you also want the function to work symbolically, you could add something like:
f[-a_] := -f[a]
I am not good at this, but how about using the TransformationFunctions of Simplify ?
For example, suppose you have the expression 2 Sin[x] + f[x] + 3 + f[-x] + g[x] + g[-x] and you want to simplify it, assuming f[x] is odd function and g[x] is even. Then we want a rule to say f[x]+f[-x]->0 and a rule g[x]+g[-x]->2 g[x].
Hence write
myRules[e_]:=e/.f[x]+f[-x]->0/.g[x]+g[-x]->2 g[x]
Simplify[2 Sin[x]+ f[x]+ 3 +f[-x]+ g[x] + g[-x],
TransformationFunctions->{Automatic,myRules}]
and this gives
3+2 g[x]+2 Sin[x]
Btw, in the above, I am using f[x] where it really should be a pattern f[x_], so that expression such as f[anything]+f[-anything] will also become zero. So, this needs to be improved to make myRules more general. Now it only works for the exact expression f[x]. I am not sure now how to improve this. Might need a delayed rule or so. Will think about it more. But you get the idea I hope.

Removing commas from multidimensional arrays

I'm having a bit of trouble removing commas from an array when I go to write it to a cell in google spreadsheets. array.join(''); doesn't seem to do the trick. I would appreciate any help. Also, anchor[i][j].join('') returns an error.
Here is a bit of code:
anchor[i][j].join('') returns an error
anchor[i].join('') doesn't seem to have an effect.
for (var i=0; i(less than) rangeKW.length-2;i++){
anchor[i] = [];
for (var j=0; j<rangeURL.length;j++){
anchor[i][j] = ahref + rangeKW[i] + ahref1 + rangeURL[j] + "</a>|";
}
}
cell.setValue("{" + anchor);
}
Suppose you have
var x = [[1,2,3],[4,5,6]]
Then either of these lines will give you "123456":
Array.prototype.concat.apply([], x).join('')
x.map(function(a){ return a.join(''); }).join('');
The first one constructs the array [1,2,3,4,5,6] and then joins it. The second one joins each inner array first, constructing ["123", "456"] and then joins that. I think the first one is likely to be a tiny bit more efficient, although we are talking peanuts here, but the second one gives you a bit more control if you want to put something different between rows and columns.
In both cases, this doesn't change the original value in x. You can assign the new value to x if that's what you want.
array.join() works with "normal" arrays, by normal I mean 1 dimension and applies to the array itself, not on an single element (error on [i][j]), beside that I don't really understand what you want to do and how your code is related to your question ...
concerning anchor[i].join('');// doesn't seem to have an effect. I don't know how many elements are in there and how they look like but the syntax is correct. You can also use toString() if you want to make it a CSV string.
EDIT : (thanks for the information in comments.)
I think the easiest way (or at least the most clear) would be to create a couple of new variables that you could log separately to see exactly what happens.
for example
var anchorString = anchor[i].join(); // or toString() they both return strings from 1D arrays
Logger.log(anchorString)
if every index i of anchor have to be in the same cell then write it like this in the i-loop :
var anchorString += anchor[i].join();
Logger.log(anchorString)