F
Filamentβ€’4w ago
itsmejyv

How to limit the decimal to $set in the other field by 2?

Forms\Components\TextInput::make('copy_interest')
->label('Interest')
->dehydrated()
->numeric()
->live(onBlur: true)
->afterStateUpdated(function ($state, $get, $set) {
$loanAmount = $get('loan_amount');
$terms = $get('terms');
$termsTotal = $terms + $state;
$total1 = $termsTotal * 0.01;
$interestTotal = $loanAmount * $total1;
$set('interest', (double) $interestTotal);
}),
Forms\Components\TextInput::make('copy_interest')
->label('Interest')
->dehydrated()
->numeric()
->live(onBlur: true)
->afterStateUpdated(function ($state, $get, $set) {
$loanAmount = $get('loan_amount');
$terms = $get('terms');
$termsTotal = $terms + $state;
$total1 = $termsTotal * 0.01;
$interestTotal = $loanAmount * $total1;
$set('interest', (double) $interestTotal);
}),
4 Replies
dissto
disstoβ€’4w ago
Probably number_format or using Number::format πŸ€”
itsmejyv
itsmejyvβ€’4w ago
yeah probably what I'm looking for but where to insert it? in the ->numeric() ?
dissto
disstoβ€’4w ago
$set('interest', number_format($interestTotal,2));
$set('interest', number_format($interestTotal,2));
I guess... Can't test it, im on mobile right now πŸ€“
itsmejyv
itsmejyvβ€’4w ago
This work, thank you!
Want results from more Discord servers?
Add your server