The specimen answers are suffixed with percentage signs: cast them to strings. Project Join onto "%" to derive unary ,[;"%"] which you can apply with each.
q),[;"%"] each string .01 xbar {?[x>1;x-100;x*100]}157.35686 0.804892
"57.35%"
"80.48%"
† For an atom argument use the ‘ternary conditional’ control structure Cond.
Why? Because Vector Conditional is an operator and all three of its arguments are evaluated. That is, whatever the result of x>1, bothx-100 and x*100 are evaluated. With Cond, either the second or third expression is evaluated; never both.
In this example, the cost is of course negligible. In other cases the expressions in the second and third arguments could be expensive.
0
Maurice Lim
On
`pct:157.35686
is wrong because you are not assigning a variable.
Your use of Vector Conditional
?suggests your argument might be a vector†.The specimen answers are rounded down to two decimal places.
The specimen answers are suffixed with percentage signs: cast them to strings. Project Join onto
"%"to derive unary,[;"%"]which you can apply witheach.† For an atom argument use the ‘ternary conditional’ control structure Cond.
Why? Because Vector Conditional is an operator and all three of its arguments are evaluated. That is, whatever the result of
x>1, bothx-100andx*100are evaluated. With Cond, either the second or third expression is evaluated; never both.In this example, the cost is of course negligible. In other cases the expressions in the second and third arguments could be expensive.