I am creati开发者_JAVA百科ng a database table in MySQL Workbench. The table I want to create is to be able to save data which is a number with a decimal point. The data I want to save is a money value which has a decimal point for the centavos. I already created a table and the data type is decimal. However, when I checked the saved data the numbers where rounded off and the centavos where gone. What I want is that it won't change anything. It will still show the exact values. Please help.
I haven't used Workbench so I can't tell you exactly how to do it, but the definition should be DECIMAL(M,D) where M is the total number of digits, and D is the total number of digits to the right of the decimal. So in your case you want D=2, and choose M>2 as appropriate for your application. If D is set to 0 is it will round off your numbers automatically (sounds like that might be your problem).
Other than that I can't think of a good reason it wouldn't store the data properly.
精彩评论