Reputation: 187
I have a simple program below. The output is 64.5 it only shows one decimal value but I wanted it to display the last two decimal values.
Ex. Your change is 64.50 USD
How can I achieve this in dart/flutter?
void main() {
double money = 80.00;
double price = 15.50;
double change = money - price;
print('Your change is $change USD');
}
Upvotes: 2
Views: 3103
Reputation: 64657
I would use the intl package from google
var formatter = new NumberFormat.currency(locale: "en_US", symbol: "$");
print('Your change is {formatter.format(change)} USD');
Upvotes: 1
Reputation: 705
Try This:
void main() {
double money = 80.00;
double price = 15.50;
double change = money - price;
print('Your change is ${change.toStringAsFixed(2)} USD');
}
Upvotes: 4