Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
onReadingChanged: {
accelerometerReading.xValue = (reading.x).toFixed(2);
accelerometerReading.yValue = (reading.y).toFixed(2);
accelerometerReading.zValue = (reading.z).toFixed(2);
}

What I have tried:

onReadingChanged: {
accelerometerReading.xValue = (reading.x).toFixed(2);
accelerometerReading.yValue = (reading.y).toFixed(2);
accelerometerReading.zValue = (reading.z).toFixed(2);
}
Posted
Updated 18-Feb-21 19:37pm
Comments
20212a 17-Feb-21 14:53pm    
No idea. What is this from?

Parenthesis are probably not required.
Member 15075381 17-Feb-21 18:00pm    
Ok
[no name] 17-Feb-21 15:10pm    
Did you try without paranthesis and you faced a problem then? If yes what problem?
KarstenK 18-Feb-21 10:29am    
Not needed, but maybe a beginner, some code changes or for clarity.

The brackets are probably not needed, but it's possible there was once a cast that required them - they just ensure that the dereference happens before the call to toFixed which would happen anyway!
 
Share this answer
 
The brackets force the
C++
.x
evaluation to happen before the
C++
.toFixed(2)
one.

Note they are not needed because of the left-to-right associativity of the member access operator (.).
See C++ Operator Precedence - cppreference.com[^].
 
Share this answer
 
This does not look like C or C++.

C++
/*Illegal return value*/onReadingChanged:/*Illegal token and missing parameter list*/ {
accelerometerReading.xValue = (reading.x).toFixed(2);
accelerometerReading.yValue = (reading.y).toFixed(2);
accelerometerReading.zValue = (reading.z).toFixed(2);
}


I have no idea what syntax this is.
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900