This question is the opposite of: CPF or CNPJ field type in VARCHAR or INT database?.
In that person wanted to put descriptive data as if they were quantity and was wrong. Now this question wants to put quantities as descriptive data, which is also wrong. It’s not a matter of good or bad practice, it’s wrong, and that’s what matters. You can do it and it might even work, but it’s wrong. Monetary values are quantities and should be stored as numbers and the correct type for it is the DECIMAL
(You can use an integer if you know what you’re doing and want to take the trouble to deal with it), don’t use other types that don’t have accuracy. A text type would guarantee accuracy, but create numerous problems, for example, how to sum up these values?
Note that in PHP you may also have problems, because by default PHP works with decimal part values without accuracy (most systems in PHP and other languages running around are wrong and programmers don’t even know this because use float
as if they were exact, see more in monetary value).
If you’re recording like this I wouldn’t worry more, you must be in control of everything that happens, and clearly something bad is happening. Whenever you need these conversions, cleanups, symbol swapping is doing something wrong, these things are necessary to fix the initial error, so fix it and you won’t need these things.
Use
float
for things other than scientific calculations is already a problem, actually. I don’t know the proper type of PHP, but theDecimal
of C# or theBigDecimal
Java does the job correctly, without losing precision. Also, the information you want to store in the bank is hardly the display string, but the value of it. If the display string is saved, I cannot, for example, sum the column values efficiently– Jefferson Quesado
Best practice would be for you to have a part field identifying the currency in which the value is expressed.
– anonimo
It certainly complicates working with strings if you are going to use these fields for calculations, don’t you agree? For example, if you want to see the input and output value of a specific year, you would have to add, imagine adding strings and symbols. Of course I can cite other problems, but that’s just to get the main idea.
– Guilherme Nascimento