toCurrency method
Converts the number to a currency string format with an optional symbol prefix.
The method formats the number according to the specified locale ('en_US' by default) and adds a currency symbol (defaults to '$') before the number. The resulting string is formatted with two decimal places.
Parameters:
symbol
(optional): The currency symbol to prepend to the formatted number string. Defaults to the dollar sign ('$').
Returns: A string representation of the number in currency format, including the specified currency symbol.
Example:
print(123456.78.toCurrency(symbol: '€')); // Outputs: €123,456.78
Implementation
String toCurrency({String symbol = '\$'}) => '$symbol${NumberFormat('#,##0.00', 'en_US').format(this)}';