在Swift中使用.spellout的NumberFormatter异常


不浪漫
2025-03-14 06:19:16 (1月前)
  1. 我正在测试一些字符串,如一,二,三,七等,以使用下面的代码查看它们是否为数字。如果字符串实际上是一个数字但是当字符串不是时崩溃,它可以正常工作......

2 条回复
  1. 0# 易米烊光 | 2019-08-31 10-32



    我们曾经使用过assign

    -1

    表示未分配的正整数。



    尝试

    1. <code>
    2. return formatter.number(from: stringValue) ?? -1
    3. </code>
    4. 并且您可以检查返回值是否大于或等于零。




    1. if(str.asNum >= 0){
      //You’re getting the correct conversation here.
      }else{
      //You’re not getting the correct conversion here.
      }

    2. </code>

登录 后才能参与评论