So, i was looking over some earlier code and found this random plus sign that should have been a syntax error, but the code worked fine and i don’t get why
tv_distance.setText("Distance: " +
( dist >= 1000 ? (String.format("%.1f", dist/1000f)) : +dist )
+ " " + metric );
The extra plus sign is at the third operand of the ternary operator:
() ? () : +dist
So what am i missing?
distis a number. The+is just specifying the sign. For example,+5is always the same as5but it is legal. Obviously, you’re much more familiar with its opposite, as in-5.