Skip to main content

Unary Positive (+)

Gives its single operand a numeric interpretation.

Details

The Unary Positive operator (+) gives its single operand a numeric interpretation. If its operand has a string value, it converts it to a numeric value. It does this by sequentially parsing the characters of the string as a number, until it encounters an invalid character. It then returns whatever leading portion of the string was a well-formed numeric.

Examples

For example:

 WRITE + "32 dollars and 64 cents"        // 32

If the string has no leading numeric characters, the Unary Positive operator gives the operand a value of zero. For example:

 WRITE + "Thirty-two dollars and 64 cents" // 0

The Unary Positive operator has no effect on numeric values. It does not alter the sign of either positive or negative numbers. For example:

 SET x = -23
 WRITE " x: ", x,! // -23
 WRITE "+x: ",+x,! // -23
FeedbackOpens in a new tab