12.07.2015 Views

ILOG OPL Development Studio Language Reference Manual

ILOG OPL Development Studio Language Reference Manual

ILOG OPL Development Studio Language Reference Manual

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Automatic conversion to a numberWhen a function or a method which expects a number as one of its arguments is passed anonnumeric value, it tries to convert this value to a number using the following rules:♦A string is parsed as a number literal. If the string does not represent a valid number literal,the conversion yields NaN.♦The Boolean true yields the number 1.♦The Boolean false yields the number 0.♦The null value yields the number 0.♦A date yields the corresponding number of milliseconds since 00:00:00 UTC,January 1, 1970.For example, if the Math.sqrt function is passed a string, this string is converted to thenumber it represents:Math.sqrt("25") 5Similarly, operators which take numeric operands attempt to convert any nonnumeric operandsto a number:"3" * "4" 12For operators that can take both strings (concatenation) and numbers (addition), such as +,the conversion to a string takes precedence over the conversion to a number (See Automaticconversion to a string.). In other words, if at least one of the operands is a string, the otheroperand is converted to a string; if none of the operands is a string, the operands are bothconverted to numbers. For example:"3" + true "3true"3 + true 4For comparison operators, such as == and >=, the conversion to a number takes precedenceover the conversion to a string. In other words, if at least one of the operands is a number, theother operand is converted to a number. If both operands are strings, the comparison is madeon strings. For example:"10" > "2" false"10" > 2 true214I L O G O P L D E V E L O P M E N T S T U D I O L A N G U A G ER E F E R E N C E M A N U A L

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!