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

Community Tip - Have a PTC product question you need answered fast? Chances are someone has asked it before. Learn about the community search. X

Round values in .js script - Vuforia Studio

TimmRo
7-Bedrock

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!

ACCEPTED SOLUTION

Accepted Solutions

I have solved the problem by rounding the values in PTC Composer based on a subscription.

 

var Wert = me.EMpro_Wert2
me.EMpro_Wert2 = Wert.toFixed(2);

 

 

View solution in original post

2 REPLIES 2

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'])
...

 

 

 

 

 

I have solved the problem by rounding the values in PTC Composer based on a subscription.

 

var Wert = me.EMpro_Wert2
me.EMpro_Wert2 = Wert.toFixed(2);

 

 

Announcements

Top Tags