isNumber: Difference between revisions
Jump to navigation
Jump to search
(New page: ==Function isNumber== Returns 1 if the parameter is a number, or 0 if it is not. ===Usage=== <source lang="mtmacro" line> [h: num = isNumber(val)] </source>) |
|||
(7 intermediate revisions by 3 users not shown) | |||
Line 1: | Line 1: | ||
== | {{MacroFunction | ||
|name=isNumber | |||
|trusted=false | |||
|version=1.3b48 | |||
|description= | |||
Test if the string parameter is a number. Returns 1 if the passed in string is a number, or 0 if it is not. Will accept integer or floating point values with or without a leading sign character. Strings containing numbers in scientific notation ({{code|1e3}}) or not in Base-10 will return false. | |||
|usage= | |||
<syntaxhighlight lang="mtmacro" line> | |||
[h: result = isNumber(string)] | |||
</syntaxhighlight > | |||
'''Parameters''' | |||
{{param|string|A string to test.}} | |||
= | |example= | ||
< | Test if the input is a valid number | ||
[h: | <syntaxhighlight lang="mtmacro" line> | ||
</ | [h: status = input("mod|0|Attack Modifier")] | ||
[h: abort(status)] | |||
[r, if(isNumber(mod) == 1), code: { | |||
[h: atkMod = number(mod)] | |||
Attack Mod is: [r: atkMod] | |||
};{ | |||
<b>Invalid input for attack modifier: [r: mod]</b> | |||
}] | |||
</syntaxhighlight> | |||
}} | |||
[[Category:Mathematical Function]] |
Latest revision as of 23:59, 9 February 2023
isNumber() Function
• Introduced in version 1.3b48
Test if the string parameter is a number. Returns 1 if the passed in string is a number, or 0 if it is not. Will accept integer or floating point values with or without a leading sign character. Strings containing numbers in scientific notation (
1e3
) or not in Base-10 will return false.Usage
[h: result = isNumber(string)]
Parameters
string
- A string to test.
Example
Test if the input is a valid number
[h: status = input("mod|0|Attack Modifier")]
[h: abort(status)]
[r, if(isNumber(mod) == 1), code: {
[h: atkMod = number(mod)]
Attack Mod is: [r: atkMod]
};{
<b>Invalid input for attack modifier: [r: mod]</b>
}]