我們有一個顫動的文本欄位,用戶可以在其中輸入金額作為 int,我們想要做的是 int 計算出的金額減去費用。可能是我無法在這里解決我做錯了什么
TextFormField(
controller: _offerAmountController,
textInputAction: TextInputAction.next,
decoration: const InputDecoration(
hintText: '5-9999',
prefixIcon: Icon(Icons.attach_money_rounded),
// labelText: 'Your Offer',
),
keyboardType: TextInputType.number,
onChanged: (offerAmount) {
double sum = int.parse(offerAmount) * 0.1;
_offer = sum as int;
}),
Text(formatCurrency.format(_offer),
style: Theme.of(context)
.textTheme
.headlineSmall
.copyWith(color: Colors.blue[700]))
final formatCurrency =
NumberFormat.simpleCurrency(locale: 'en_AU', decimalDigits: 0);
uj5u.com熱心網友回復:
嘗試這個:
setState(() {
_offer = sum.toInt();
});
uj5u.com熱心網友回復:
嘗試這個
setState(() {
_offer = (sum).round();
});
或這個
setState(() {
_offer = sum.toInt();
});
如果您需要以下代碼,您也可以試試這個
double d = 50.5;
int i = d.toInt(); // i = 50
int i = d.round(); // i = 51
int i = d.ceil(); // i = 51
int i = d.floor(); // i = 50
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/431592.html
