Just trying to return a price in json from our API, this needs to be formatted as a float with two decimal place. Currently when I float it returns without the decimals but without float it returns as a string and I would like it as a float.
public function repairs(Collection $repairs) : Collection
{
return $repairs->map(function ($repair) {
return [
"id" => $repair->id,
"title" => $repair->problem->title,
"price" => (float) $repair->price
];
});
}
results in:
"repairs": {
"411": {
"id": 411,
"title": "Screen",
"price": 235.99
},
"419": {
"id": 419,
"title": "Charger Port",
"price": 40
},
"582": {
"id": 582,
"title": "Back Glass",
"price": 40
}
}