PHP float/double stored as MySQL DECIMAL

前端 未结 2 693
温柔的废话
温柔的废话 2021-01-19 18:28

i ran into a really strange problem with storing values in MySQL. The premise:

I have a table that uses DECIMAL(15,8) to store monetary values (like the

2条回答
  •  情书的邮戳
    2021-01-19 19:01

    Replace the , with . before inserting into db:

    $value = str_replace( ',', '.', $value);
    

    This will create a valid number, that can be safely inserted into the database. Or just add it just inside your query:

    INSERT INTO `random_table_name` SET currency_value = '" . str_replace( ',', '.', $value ) . "'
    

提交回复
热议问题