正在解析 flutter/dart 中的数字

Parsing number in flutter/dart

我正在尝试将字符串“78,74”(这是巴西格式中的有效数字)解析为两倍,但我收到格式异常并且找不到任何解析方法。 .. 已经在国际文档中搜索过,但没有任何帮助。

我不想将“,”替换为“.”因为我认为这一定是一种使用 CultureInfo

来解析它的方法

我的代码是这样的

String x = "78,74";

double d = double.tryParse(x)

您可以使用 intl 库中的 double d = NumberFormat('pt_Br').parse(x)。您将需要添加依赖项。

可以在 package:intl. For this particular case, you're looking for the parse method from NumberFormat 中找到对解析数字的本地化支持。