【问题标题】:How to convert a number from 20,95 to 20.95 in Dart/Flutter?如何在 Dart/Flutter 中将数字从 20,95 转换为 20.95?
【发布时间】:2021-08-19 17:59:18
【问题描述】:

我从电子表格中得到一个字符串 (20.95),需要将其转换为 Double (20.95)。

我尝试使用Intl 包,使用

double.parse(NumberFormat.currency(locale: 'en_US').format(price)

但它总是用逗号返回值。

错误:FormatException:无效的双精度 20,95

【问题讨论】:

    标签: flutter dart intl


    【解决方案1】:

    以下代码将逗号替换为点,然后将其解析为双精度。

    double.parse(yourString.replaceAll(",", ".")),
    

    【讨论】:

      猜你喜欢
      • 2022-01-08
      • 2020-11-05
      • 1970-01-01
      • 2021-11-10
      • 1970-01-01
      • 2022-12-19
      • 2018-12-13
      • 2020-09-12
      • 2019-05-30
      相关资源
      最近更新 更多