Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Komayo's avatar

Decimal column / Float column

Hello guys,

Iam having here a issue, need some help of you. Iam trying to save a value to mysql (Decimal column). In my laravel schema as

    $table->decimal('sorder_by', 4, 2);

then in my php i have in the database seeder insert statement.

    ... 'sorder_by' => 20.42 ...

but always saves in mysql as 20,42 with a comma..... Tryed several diferent ways, cant make it save with a dot....

What iam doing wrong?

0 likes
6 replies
jakeryansmith's avatar

I don't believe mySQL is even capable of saving a decimal value with a comma. Are you sure this is how it's saved, or is this just how it looks after you retrieve it from the database?

On a side note, it is possible to format the number in php to look the way you want using the number_format function

number_format($number, 2, '.', '');
1 like
oeb's avatar

I suspect that this might have something to do with localization. There are a number of countries such as France, Poland and Denmark that use "," as a decimal separator.

Where are you seeing this comma? Is it direct in the database when using the mysql binary or in your pulled in to your laravel app (Or is are you looking at it with a different tool like phpmyadmin or mysql workbench)? As far as I am aware @jakeryansmith is correct about mysql using a comma as a decimal separator, it's not localized like that.

1 like
Komayo's avatar

@jakeryansmith iam pretty sure it saves with the comma, iam using heidisql to view the database data, and it shows with the commas. I already tryed that number_format function at the insert statement, still same result.

@oeb i am seing in the raw database, using heidisql windows application. Value always get saved with comma and not dot.

Komayo's avatar
Komayo
OP
Best Answer
Level 2

@jakeryansmith and @oeb, found the issue...

Its HeidiSQL option: 'Alternating row background: Local number format'. Seems a localization auto formatting of HeidiSQL. Disabled, and i got the right values. Thank you.

2 likes
jakeryansmith's avatar

Perhaps this could be a localization setting heidisql for how it displays data.

The number_format trick was meant for displaying the value in your views after you pull from the DB, not for inserting into DB.

oeb's avatar

@Komayo, heidisql does preform number localization. From what I can gather, you should be able to change this by going Tools-> Preferences-> Text formatting-> Local number format.

This only affects how the information is DISPLAYED within heidisql, the mysql server it self is storing the number correctly, and your app should display it correctly as well (Unless you are localizing that too).

Please or to participate in this conversation.