F
Filamentβ€’4mo 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β€’4mo ago
Probably number_format or using Number::format πŸ€”
itsmejyv
itsmejyvOPβ€’4mo ago
yeah probably what I'm looking for but where to insert it? in the ->numeric() ?
dissto
disstoβ€’4mo 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
itsmejyvOPβ€’4mo ago
This work, thank you!
Want results from more Discord servers?
Add your server