[英]PHP/MySQL Convert and save formatted prices
I need store in MySQL all prices submitted by users.我需要将用户提交的所有价格存储在 MySQL 中。 The prices submitted by the users can contain these formats:用户提交的价格可以包含以下格式:
123.456,78 (ARG format)
123,456.78 (US format)
123456,78 (ARG simplified format)
123456.78 (US simplified format)
In MySQL i have a column named "price" of type decimal
.在 MySQL 中,我有一列名为“price”的类型为decimal
。
My question is, How can i convert those formats to decimal
to save them in my database?, or, How can i convert values to "ARG simplified format" to save all as varchar
?我的问题是,如何将这些格式转换为decimal
以将它们保存在我的数据库中?,或者,如何将值转换为“ARG 简化格式”以将所有值保存为varchar
? I need all with the same format (two decimals).我需要所有格式相同(两位小数)。
I've tried to help you with your previous question , that is similar to this one.我试图帮助您解决上一个问题,这与这个问题类似。
My solution is to limit/format the user input on the client side, for that you can use the html5
input type=number
with a step
(increment) of 0.01
.我的解决方案是在客户端限制/格式化用户输入,为此您可以使用html5
输入type=number
, step
(增量)为0.01
。
<input type="number" step="0.01" value='0.00' placeholder='0.00'>
Notes:笔记:
Make sure you validate the values on the server side too.确保您也验证服务器端的值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.