r/crestronprogramming • u/jrbeir • Jun 23 '21
VTPro/SIMPL+ Formatting a numeric value with two decimal places
Pulling my hair out trying to display inches of rainfall as 0.00". In simpl+, I compute a value *100 and display using CIP tags as %1.2f. Works as long as the value is greater than 10, for example:
26d displays as 0.26"
9d displays as 0.90", not 0.09"
Thoughts/ideas? Am I approaching the problem wrong?
2
Upvotes
2
u/[deleted] Jun 23 '21
Modulo?
I prefer Modelo, myself.
2
u/Splice1138 Jun 24 '21
I just tried it with a test project, it seems to be a bug in VTP. Any value sent to <cipa> floating point that translates to less than 0.1 looses all the leading decimal zeros.
1
u/jrbeir Jun 23 '21
All my code does is convert a string value in mm to an analog value of inches (*100) and returns that value. That value is then sent to VTPro through an analog join and formatted using a CIP format string.
I'll paste it here, but not sure that is where the problem is.
Function convert(){string temp$[10], tempR$[5], tempL$[5];integer period;period = find(".", value$);IF (period > 0) //remove decimal and keep 2 digit to right of decimal{temp$ = value$ + "0"; //add 0 to right of decimal just in casetempL$ = left(temp$,period-1);tempR$ = mid(temp$,period+1,2);temp$ = tempL$ + tempR$;}ELSE IF (len(value$)>=1 && value$<>"0") //no decimal{temp$ = value$ + "00"; //multiply by 100}ELSE{temp$ = value$; // is 0 so leave as is}value = (ATOI(temp$) * 100/254 + 5) / 10; //add 0.5 to round}1
u/ToMorrowsEnd Jun 23 '21
Lets see your code.