I have problem with some table in MySQL database and read it with Laravel4. This is how to look like results when put float(6,2) coloumn for price:
And this is look like if I put same column into varchar(6):
Did someone know what is the problem and how to fix it? I have other table with float(5,2) column and laravel show results correctly. I use only Model::get() to get data from database and Model (model is name of table in both times) is simple:
class Model extends Eloquent
{
use SoftDeletingTrait;
protected $dates = ['deleted_at'];
protected $primaryKey = 'idreceive';
protected $table = 'model';
}
The problem is that you're using an comma ,
instead of an dot .
to separate the float decimal.
So you need to convert your input from this:
121,51
To this:
121.15
Here's an SO question on how to solve this problem
Code from that answer:
$string_number = '1.512.523,55';
// NOTE: You don't really have to use floatval() here, it's just to prove that it's a legitimate float value.
$number = floatval(str_replace(',', '.', str_replace('.', '', $string_number)));