int() function
Monkey Targets Forums/Android/int() function
| ||
Hi I get an error with int(s:string) function when string is NaN (in html it works and returns NaN). Do I need to check all chars of the string before converting it? Or is there a way to get that Int() function work with a flag or something. (can't find that function in documentation/function) thx ako |
| ||
Int($) is not actually a function, it's just a typecast. String typecasting in Monkey generally delegates directly to the target language, so if the target language can't handle casting NaN, it will fail. Maybe do a null check on the string first (technically strings in Monkey are not nullable, but it might handle your use case). Try something like this: Local i:Int = 0 If str Then i = Int(str) In this case, i will be 0 if str was either an empty string, or (hopefully) NaN. |