MCPcopy Create free account
hub / github.com/PageBot/PageBot / filterValue2Int

Function filterValue2Int

Lib/pagebot/toolbox/transformer.py:299–309  ·  view source on GitHub ↗

Filter all numeric characters from the string and answer the resulting integer. Answer 0 if no digits are found. If s is already a number, then answer it as rounded int.

(s)

Source from the content-addressed store, hash-verified

297 return l
298
299def filterValue2Int(s):
300 """Filter all numeric characters from the string and answer the resulting
301 integer. Answer 0 if no digits are found. If s is already a number, then
302 answer it as rounded int."""
303 if isinstance(s, (int, float)):
304 return int(round(s))
305 digits = '0'
306 for c in s:
307 if c in '0123456789':
308 digits += c
309 return asInt(digits)
310
311# B O O L E A N
312

Callers

nothing calls this directly

Calls 1

asIntFunction · 0.85

Tested by

no test coverage detected