Checking if string is numeric in dart

后端 未结 4 1115
悲哀的现实
悲哀的现实 2021-02-02 06:59

I need to find out if a string is numeric in dart. It needs to return true on any valid number type in dart. So far, my solution is



        
4条回答
  •  情歌与酒
    2021-02-02 07:35

    In Dart 2 this method is deprecated

    int.parse(s, onError: (e) => null)

    instead, use

     bool _isNumeric(String str) {
        if(str == null) {
          return false;
        }
        return double.tryParse(str) != null;
      }
    

提交回复
热议问题