Flutter provides the NumberFormat
class that can be used to convert a double with low value into currency.
Here is an example code:
import 'package:flutter/material.dart';
import 'package:intl/intl.dart';
class CurrencyConverter extends StatelessWidget {
final double value;
CurrencyConverter({@required this.value});
@override
Widget build(BuildContext context) {
return Text(
'${NumberFormat.currency(locale: 'en_US', symbol: '\$').format(value)}',
style: TextStyle(fontSize: 16.0),
);
}
}
In the Text
widget, the NumberFormat
class is used with the currency
method to format the double value into currency. The locale
parameter is used to set the currency format to US dollars and the symbol
parameter is used to set the currency symbol to $
.
This widget can be used like this:
CurrencyConverter(value: 10.50)
This will display $10.50
on the screen.
Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss
Asked: 2023-06-08 07:38:25 +0000
Seen: 17 times
Last updated: Jun 08 '23
How can zooming similar to desktop be achieved in HTML webview browser using Flutter?
In what way can the appleID signin be utilized in flutter?
How to maintain state across different pages using flutter?
How can I change a CameraImage Stream into bytes or a file in Flutter?
How can the current page context be obtained by a Flutter GetX controller?