> Functions
Converts a value to a number. If the value is a string, the number function tries to convert it to a number; if the value is already a number, the function returns it as is; for any other type, it returns 0.
In JavaScript, Number(value) returns NaN when the conversion fails, where number returns 0 in LeekScript. Test the result with Number.isNaN(), never with === NaN: NaN is equal to nothing, not even itself. Watch out for the edge cases: Number("") and Number(null) are 0, Number("0x10") is 16. Finally, Number("12abc") is NaN while parseInt("12abc") is 12 — parseInt stops at the first invalid character, Number requires the whole string to be a number.
In Python there is no single conversion: int(value) gives an integer, float(value) a float. On a string that is not a number, both raise a ValueError instead of returning 0 like number in LeekScript — float("abc") and float("") fail, and so does int("12.5"), because int() does not accept a decimal part: write int(float("12.5")). Surrounding spaces are tolerated, float(" 12 ") is 12.0. Applied to a float, int() truncates toward zero: int(12.9) is 12 and int(-12.9) is -12. Wrap the call in a try / except ValueError as soon as the string does not come from you.
number("12345") // 12345 number("3.14159") // 3.14159 number("hello") // 0
Impossible de charger les données du jeu.
Vérifiez votre connexion et réessayez.