cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Round values in .js script - Vuforia Studio

Highlighted
Visitor

Round values in .js script - Vuforia Studio

Hello, everybody,

 

I'm stuck on what is probably a simple function.


I want to round an internal parameter to two decimal places in Vuforia Studio, but I don't know how.
The option to assign a filter directly to the widget is not an option for me, because I assign the widget text in a function in the .js file.

 

Here is a small excerpt:

TimmRo_0-1584526522336.png

The following parameters should be rounded to two decimal places:

  • $scope.app.params.EMpro_W1
  • $scope.app.params.EMpro_W2
  • $scope.app.params.EMpro_W3

The internal parameters are assigned a value from the ThingWorx Composer with the data type #Number.

 

-----
If there is no possibility here, do you know how I can round a value in the ThingWorx Composer with a subscription ?

 

I would be very pleased about any help!
Thanks a lot!

1 REPLY 1
Highlighted

Re: Round values in .js script - Vuforia Studio

Hi @TimmRo ,

one possible way to do this is to use the JavaScript toFixed() method which will round to the number what you specify as argument:

 

 

 

...
 $scope.app.params['eyepos'] ="eyepos=("+fargs.position[0].toFixed(2)+","+fargs.position[1].toFixed(2)+","+fargs.position[2].toFixed(2)+")";
...

 

 

 

If you parameter is a string you can use the Number() to convert it as string then "fix" the number of the dec places

 

 

 

 ...
 $scope.app.params['TEST'] ="VALUE WITH ONE DEC PLACE="+Number($scope.app.params['TESTSTRINGNUMBER']).toFixed(1);
console.log($scope.app.params['TEST'])
...

 

 

 

 

 

Announcements
Topics available:
AR/VR for Data Optimization AR/VR for Security and Control AR/VR for Inspection