Convert Large Values Of String To Number Laravel. (int) Gives Wrong Value
When I do:
$var = (int)('5000'); dd($var); //outputs 5000
$query = Mymodel::find($id); dd($query->loan_amount); //outputs "1,040,000.00"
$var = (int)($query->loan_amount); dd($var); //outputs 1
$query = Mymodel::find($id); dd($query->loan_amount); //outputs the picture below
May I know why? And how do I fix the large numbers?
Model Collection has
104000 But output shows
1,040,000.00. So you might have used
Accessor / Mutator.
You can try this to convert,
// remove `,` then convert. $loan_amount = (int) (str_ireplace(',', '', $query->loan_amount)); dd($loan_amount);
Standard way to format
model attributes in
laravel is accessors & mutators, Please check it out.
- → "failed to open stream" error when executing "migrate:make"
- → October CMS Plugin Routes.php not registering
- → OctoberCMS Migrate Table
- → OctoberCMS Rain User plugin not working or redirecting
- → October CMS Custom Mail Layout
- → October CMS - How to correctly route
- → October CMS create a multi select Form field
- → October CMS - Conditionally Load a Different Page
- → How to disable assets combining on development in OctoberCMS
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → OctoberCms component: How to display all ID(items) instead of sorting only one ID?
- → In OctoberCMS how do you find the hint path?
- → How to register middlewares in OctoberCMS plugin?