Marcie Posted May 16, 2019 Share Posted May 16, 2019 I have a signal based on the formula: $a/($b+$c) and I want the result to display as a percentage (33%) instead of a decimal (0.333). I haven't had much luck adding % as a unit. How can I change what's displayed? Link to comment Share on other sites More sharing options...
Guest Jon Peterson Posted May 16, 2019 Share Posted May 16, 2019 Hi Marcie, This should do it: ($a/($b+$c)).setUnits('%') Presumably your $a/($b+$c) results are unit less. If not, you can set the units on each variable to get the proper results (or remove the units with .setUnits(' '). I've attached a screen shot of a test I just did. Let us know how this works. Regards, Jon Peterson Link to comment Share on other sites More sharing options...
Marcie Posted May 16, 2019 Author Share Posted May 16, 2019 Thank you for your help. My signals don't have units. The displayed result is 0.333 % now, instead of 33%, though. The formula is 2/(2+4) from the last 3 rows of the table. Link to comment Share on other sites More sharing options...
Seeq Team Ben Johnson Posted May 16, 2019 Seeq Team Share Posted May 16, 2019 The alternative to setUnits is convertUnits. The former just adds overrides the current value with the new unit, the latter applies the math needed to the existing values. For your case you should probably use ($a/($b+$c)).convertUnits('%') Link to comment Share on other sites More sharing options...
Guest Jon Peterson Posted May 16, 2019 Share Posted May 16, 2019 @Marcie--I just updated my test and confirmed the convertUnits('%') should do it. I just edited out the below--operator error on my part. Everything is working as expected. @Ben Johnson, Can you explain the logic Seeq uses with the setUnits? I did the following quick tests: 1. My first test was using two signals, both having the units of F. Presumably the ratio of the two signals results in a unit of 1. Thus, when using setUnits the conversion to percent works. 2. I then did the same test, but with two signals from our PI Server that had no units. setUnits did not work, but convertUnits did. 3. Same test as 2, but, I first set the units to F, then did the math. I would expect this to work the same as 1. But it did not. Thanks, Jon Link to comment Share on other sites More sharing options...
Marcie Posted May 16, 2019 Author Share Posted May 16, 2019 Convert units worked great! Thank you! Link to comment Share on other sites More sharing options...
Seeq Team Ben Johnson Posted May 16, 2019 Seeq Team Share Posted May 16, 2019 ConvertUnits requires a compatible units of its input and will do the scaling. Some examples 5m.convertUnits('cm') = 500cm. 5m.setUnits('cm') = 5cm 5m.setUnits('g') = 5g 5m.convertUnits('g') is an error I'm a bit surprised by the failure in your 2nd case. setUnits should never fail (almost - there are edge cases in converting string and numeric). I imagine the issue is that the underlying signals have incompatible units for the math prior to the setUnits. If you have the formulas you tried, we can see if there are precedence issues vs actual bugs. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.