-2

I'm trying to convert string to decimal in flutter with two decimal places

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

the result is 100.0

How can I achieve 100.00 ?

Favaz
  • 33
  • 7
  • 1
    This post might be able to point you in the right direction: https://stackoverflow.com/questions/28419255/how-do-you-round-a-double-in-dart-to-a-given-degree-of-precision-after-the-decim – fravolt Dec 27 '21 at 08:55

1 Answers1

3

Please refer to below code

code snippet

For more info on toStringAsFixed. Please refer to this link description

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

Output:
Result: 19.00
Tejaswini Dev
  • 1,311
  • 2
  • 8
  • 20