【问题标题】:parse string to double with 2 decimal places in flutter在颤动中将字符串解析为带有 2 位小数的双倍
【发布时间】:2022-01-26 07:05:22
【问题描述】:

我正在尝试将字符串转换为小数点后两位的小数

_accountStatementStore.totalIn = "100";
 Text(
              "${double.parse(_accountStatementStore.totalIn!)}",
              style: TextStyle(
                  fontSize: 16.0,
                  fontWeight: FontWeight.normal,
                  color: Colors.green[700]),
            ),

结果是 100.0

我怎样才能达到100.00

【问题讨论】:

标签: flutter dart


【解决方案1】:

请参考以下代码

code snippet

有关 toStringAsFixed 的更多信息。 请参考这个link description

  String num = "19";
  double val = double.parse(num);
    print('Result: ${val.toStringAsFixed(2)}');

Output:
Result: 19.00

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2010-12-07
    • 2016-10-19
    • 1970-01-01
    • 2022-06-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-06
    相关资源
    最近更新 更多