Type conversion functions¶
These functions convert values of one type into another type, if possible. All of these functions take a single argument of arbitrary type, and return the result of the type corresponding to the name of the function.
bool(x)¶
Converts its argument into a boolean value.
- If - xis already a boolean, then it returns the argument as-is.
- If - xis numeric, then the result is- falsewhen- xis- 0, and- truefor all other values of- x.
- If - xis string, then the function will check whether that string can be found within- YarnProject.trueValuesor- YarnProject.falseValuessets. If yes, then it will return the- true/- falsevalue respectively. Otherwise, an error will be thrown.
number(x)¶
Converts its argument x into a numeric value.
- If - xis boolean, then it returns- 1for- trueand- 0for- false.
- If - xis numeric, then it is returned unmodified.
- If - xis string, then the function attempts to parse that string as a number. A runtime exception will be raised if- xdoes not have a valid format for a number. The following formats are recognized:- integer: - "-3",- "214"
- decimal: - "0.745",- "3.14159",- ".1",- "-3."
- scientific: - "2e5",- "3.11e-05"
- hexadecimal: - "0xDEAD",- "0x7F"
 
string(x)¶
Converts its argument x into a string value.
- If - xis boolean, returns strings- "true"or- "false".
- If - xis numeric, converts it into a string representation using the standard Dart’s- .toString()method, which attempts to produce the shortest string that can represent the number- x. In particular,- if - xis integer-valued, returns its decimal representation without a decimal point;
- if - xis a double in the range- 1e-6to- 1e21, returns its decimal representation with a decimal point;
- for all other doubles, returns - xwritten in the scientific (exponential) format.
 
- If - xis a string, then it is returned as-is.
