I have sales quantity as a in put which contains negative value also I have to parse it to all positive since there is no abs() function available in logic app
One workaround to make it positive is to use sub() or mul() operations.
output
Expression :
sub(0,variables('x'))
mul(-1,variables('x'))
Related
I'm simplifying this down but let's say I have a payable function called myFunction. After a transaction is made (via React) I want to update the number property of a struct within the contract called myStruct using basic math. Let's say I want to calculate it as 1 minus the new contract balance.
function myFunction() public payable {
myStruct.number = 1 - address(this).balance;
}
If I send a 0.01 ETH to this function on a new contract with a 0 balance, myStruct.number renders out as 15792089237316195423570985008687907853269984665640564039457574007913129639937
I can't for the life of me figure out why. If I do basic math without using address(this).balance or msg.value then it's fine and renders correctly. But every time I try to involve either of those, I get these wild results.
Help would be much appreciated!
I guess myStruct.number is a uint.
by declaring uint you are declaring a 256-bit int that accepts only positive numbers.
when you send 0.01 ETH to the contract balance, you are actually receiving 10000000000000000 WEI (you must remember that 1 ETH is formed by 1e18 WEI)
calling
address(this).balance
you will get 10000000000000000 as a result, so you're trying to do
1 - 10000000000000000
and since uint only accepts positive numbers, you get that result.
I suggest you use the SafeMath library to avoid these errors
https://docs.openzeppelin.com/contracts/2.x/api/math
Hey you have to use SafeMath library. Solidity works different than other languages on variables.
using SafeMath for uint256;
Also import SafeMath.sol from Openzeppelin's library, then you can continue with much more accurate results.
How to check a given napi_value of type napi_number is an integer or decimal (a number with fractional value) by using node.js native N-API function .
Look like there is no isInt() or isDouble() equivalent function in N-API (we don’t want to use V8 function call either). Let us consider a scenario where we are calling a native addon function f1() from JavaScript by passing a JavaScript object as argument as shown in the snippet.
let obj = { n1: 123, n2: 123.45 };
myaddon.f1( obj );
The native function f1() want to extract value associated with the keys n1 and n2 by calling the best fit value extraction N-API function. For example to extract value of n1 it may be best to use one of napi_get_value_int* and similarly for the n2 the double is a better choice.
napi_get_value_double
napi_get_value_int32
napi_get_value_uint32
napi_get_value_int64
Unfortunately I could not find any N-API function to verify the derivative of napi_number property. Have you come across similar situation, if so how did you solve this problem?
https://nodejs.org/api/n-api.html
A request has been opened with node-addon-api team regarding this feature and they provided an answer that sound logical. I thought of sharing the answer with this community that may help similar queries others may have. Here is the answer from node-addon-api team
While handling numbers with JavaScript, it is important to know
that all numbers in JavaScript are double-precision 64 bit IEEE
754 values (despite some engines like v8 might have additional
represents on small integers, there is no such definition in ECMA spec
and no way to determine these types of number in JavaScript).
napi_get_value_{double,int32,uint32,int64} just convert these value to
its desired one. There might be a precision loss in the conversion. If
a determined number is required in the case, use BigInt instead.
I am using angularJS and Angular Material Design.
For one of the amount field i have input box as below which displays calculated field.
Whenever the value is stored it is stored as comma separated i.e. 19,999.9984 which is not a problem for me.
But whenever i use this value for another calculation, i get NaN.
$scope.txn.toUnits = $scope.txn.toAmount / $scope.txn.toPrice
Above expression end up with NaN since there is a comma in toAmount value 19,999.9984
Is there any angular way to resolve this ?
You could use the parseFloat function
This is a best solution to do this if it interests you :
http://numeraljs.com/
can any one explain why(how) the xtype: numberfield value is going to auto correct(change) if am providing more than a 16 digits value.
For Example:
22222222222222222 is changed to 22222222222222224
222222222222222222 is changed to 222222222222222200
2222222222222222222 is changed to 2222222222222222300
22222222222222222222 is changed to 22222222222222220000
222222222222222222222 is changed to 222222222222222230000
2222222222222222222222 is changed to 2.2222222222222222e+21
22222222222222222222222 is changed to 2.2222222222222223e+22
Which results in my page after rendering as shown below when get the value through in my component jsp page
NumberFieldTestValue:<%= properties.get("numberfieldname","") %>
Resulting as below
NumberFieldTestValue: 2.2222222222222223e+22
The problem
This behavior is caused by the fact that the dialog behavior is implemented in JavaScript. The numbers you're having problems with cannot be represented in it.
The language conforms to the ECMASCRIPT 5.1 specification.
To quote the Number type description
all the positive and negative integers whose magnitude is no greater
than 2^53 are representable in the Number type
The base 2 logarithm of 2222222222222222222222 is about 70, which means the number exceeds the maximum value. Hence your problems.
All in all, if you check your examples in a plain JS console in a browser, the same behavior will be displayed so this is not really a CQ problem.
Solution 1 - use a different type
To avoid this, you could potentially use xtype="textfield" and validate it against a regular expression to see if it consists of numbers only. Then you'd have to make sure to use a type capable of holding such numbers at the backend (like BigInteger).
The field could look like this:
<numberOfSandGrains
jcr:primaryType="cq:Widget"
fieldLabel="Number of grains of sand at the beach"
name="./grainsCount"
regex="/\d+/"
regexText="Please enter a numeric value."
xtype="textfield"/>
Solution 2 - change scale
Another option is to change the logic behind the configuration and use some different units if applicable. For instance, if the value 2222222222222222222222 is a number of grams (weight of an object/substance), it makes perfect sense to read it in metric tons instead (at least in many cases). The author could probably do without entering such humongous numbers.
You'll need to be extra-careful if you go this way.
UserModel.query (self.login == login, self.name == name, ancestor = ancestor_key)
This is a Python statement to retrieve data from the GAE datastore. Can you explain why I use one equality sign (=) for the ancestor, and two signs (==) for other properties?
When I use two equality signs, a statement like self.login == login should return a boolean value, that is then passed to the function. But it doesn't work this way, right?
For the second part of your question:
python lets you overload 'equals' (and less-than and greather-than and so on) for a class (and you can have it return anything, not just true/false), and ndb has done just that for Properties to return query FilterNodes. Check the source: https://code.google.com/p/appengine-ndb-experiment/source/browse/ndb/model.py#858
You are mixing up a comparison with an assignment.
See the docs https://developers.google.com/appengine/docs/python/ndb/queries#filter_by_prop
The factory for creating a query object for this Kind takes an ancestor argument which defines the scope of the query for the given ancestor. It also accepts a number of expressions that defines filters. The use of self.login == login is an expression defining a filter.
I don't understand the last part of your question.
Another way of defining the query would be
UserModel.query(ancestor=ancestor_key).filter(self.login==login)
The ability to supply filters in query() is just a short cut for this form.