makeDecimal method

String makeDecimal(
  1. String amount
)

Converts the provided amount to a valid decimal format.

Parameters:

  • amount: The amount to be converted.

Returns: A String representing the valid decimal format of the amount.

Implementation

String makeDecimal(String amount) {
  if (isValidDecimal(amount)) {
    try {
      double parsedAmount = double.parse(amount);
      return parsedAmount.toStringAsFixed(2);
    } catch (e) {
      return '0.00';
    }
  }

  // If the amount is not a valid decimal, try converting it
  try {
    double parsedAmount = double.parse(amount);
    return parsedAmount.toStringAsFixed(2);
  } catch (e) {
    return '0.00';
  }
}