If you need a certain number of decimals in the presentation part of your app (vue), I would just format it there to ensure the correct structure
data.toFixed(2) //2 decimals
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
In my controller I am running some services to map data and format specific values to a specific number of decimal points. This includes trailing zeros. But when I pass the data as a prop to Vue through Inertia, the trailing zeros are removed. Example:
// Controller function
public function index(Service $service)
{
$data = $service->mapData();
// dd($data) <- this returns a floating point value such as 3.0
Inertia::render('my-page', [
'data' => $data
];
}
If I dd($data), it will display correctly something like 3.0, notice the trailing zero here. But going to my Vue component and checking Vue Dev Tools, that same prop comes in as 3, an integer. However if the data is not a trailing zero like 3.5, the Vue prop is still 3.5. I'm not sure why there is an inconsistency here.
Is there a way to prevent this or is it a default action that I have to address Vue side? I could convert to a string in the controller, but I'd rather not do that as the values may be used for calculations.
Please or to participate in this conversation.