Is there a way with NumberFormat
to display :
Thanks for your help.
Here's an example from a flutter implementation: import 'package:intl/intl. dart'; final formatCurrency = new NumberFormat. simpleCurrency(); new Expanded( child: new Center( child: new Text('${formatCurrency.
Use double. tryParse("10000") or double. parse("10000") , after this just format.
The Intl. NumberFormat() object enables language-sensitive number formatting. We can use this to convert currency, numbers, percentages, units, and other notation into formatted strings. This is particularly useful in eCommerce applications, with examples like displaying an item price or recipt printing.
Actually, I think it's easier to go with truncateToDouble()
and toStringAsFixed()
and not use NumberFormat
at all:
n.toStringAsFixed(n.truncateToDouble() == n ? 0 : 2);
So for example:
main() { double n1 = 15.00; double n2 = 15.50; print(format(n1)); print(format(n2)); } String format(double n) { return n.toStringAsFixed(n.truncateToDouble() == n ? 0 : 2); }
Prints to console:
15 15.50
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With