如何在 Flutter 中将数字格式化为货币字符串
How to format numbers as currency strings in Flutter
***大家好,我如何将下面的代码转换为货币 Dart/Flutter?
flutter 中有一个 class 命名数字格式,但我不太明白。你能帮忙解决这个问题吗?
示例“$ 3,500.00”***
----
@override
Widget build(BuildContext context) {
return Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Text(
"Toplam Masraf: ",
style: TextStyle(
color: Colors.orange.shade500,
fontSize: 15,
fontWeight: FontWeight.w600),
),
Text(
toplam >= 0 ? "${toplam.toStringAsFixed(2)}" : "0.00".toString(),
style: TextStyle(
color: Colors.orange.shade900,
fontSize: 20,
fontWeight: FontWeight.w800),
),
Text(
"₺",
style: TextStyle(
color: Colors.orange.shade900,
fontSize: 25,
fontWeight: FontWeight.w800),
)
],
);
}
也许 NumberFormat
class 会对您有所帮助:https://api.flutter.dev/flutter/intl/NumberFormat-class.html
你试过这些例子了吗?
***大家好,我如何将下面的代码转换为货币 Dart/Flutter?
flutter 中有一个 class 命名数字格式,但我不太明白。你能帮忙解决这个问题吗? 示例“$ 3,500.00”***
----
@override
Widget build(BuildContext context) {
return Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Text(
"Toplam Masraf: ",
style: TextStyle(
color: Colors.orange.shade500,
fontSize: 15,
fontWeight: FontWeight.w600),
),
Text(
toplam >= 0 ? "${toplam.toStringAsFixed(2)}" : "0.00".toString(),
style: TextStyle(
color: Colors.orange.shade900,
fontSize: 20,
fontWeight: FontWeight.w800),
),
Text(
"₺",
style: TextStyle(
color: Colors.orange.shade900,
fontSize: 25,
fontWeight: FontWeight.w800),
)
],
);
}
也许 NumberFormat
class 会对您有所帮助:https://api.flutter.dev/flutter/intl/NumberFormat-class.html
你试过这些例子了吗?