You should not store it as a float, either multiply it and store it as an int or store it as a numeric.
Aug 24, 2023
7
Level 1
Storing float numbers in SQLite
I use SQLite database in my project. I have a table with float columns:
$table->unsignedFloat(column: 'amount', places: 2)->nullable();
My request validation rules are:
'amount' => 'required|numeric',
When I create a model with a float value:
Amount::create([
'amount' => $request->amount,
]);
values after floating point are lost. Request input 'amount' contains 923442.25, but it is stored as 923442.00
How can I keep the value intact?
Level 74
@NameUnknown There seems to be a bit of a debate how to store it in SQLIte. I suggest multiply with 100 and then divide with 100 before displaying
1 like
Please or to participate in this conversation.