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

Community Tip - Learn all about PTC Community Badges. Engage with PTC and see how many you can earn! X

Round values in .js script - Vuforia Studio

TimmRo
5-Regular Member

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 ACCEPTED SOLUTION

Accepted Solutions
TimmRo
5-Regular Member
(To:RolandRaytchev)

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

 

 

 

 

 

TimmRo
5-Regular Member
(To:RolandRaytchev)

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);

 

 

Top Tags