-1

I need store in MySQL all prices submitted by users. 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.

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? I need all with the same format (two decimals).

Manux22
  • 323
  • 1
  • 5
  • 16
  • Why negative votes? Explain your reasons... – Manux22 Apr 20 '16 at 22:58
  • 2
    Why don't you limit the user input so you can format the currency as soon as the user types ? PS:I didn't down vote you. Also, and because you're a new stack user, make sure you read [How do I ask a good question?](http://stackoverflow.com/help/how-to-ask). GL – Pedro Lobito Apr 20 '16 at 23:07
  • This is an application problem. It would be clumsy to try to do it in SQL. Think of it this way: a database is for data; formatting (incoming or outgoing) should be handled by the application. (No, I did not downvote you either.) – Rick James Apr 22 '16 at 03:09

1 Answers1

1

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.

    <input type="number" step="0.01" value='0.00' placeholder='0.00'>

Notes:

Make sure you validate the values on the server side too.

Pedro Lobito
  • 94,083
  • 31
  • 258
  • 268
  • 1
    yes, sorry but in the previous question i expressed wrong, @PedroLobito have reason. Is not easy for me write in english, sorry. This is a solution, but in my country, decimal is separated by a comma (but this is not a problem). I avoided this solution because I had everything planned to use the other format. But I think that not have other solution. Thanks – Manux22 Apr 20 '16 at 23:30