PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, August 11, 2022

[FIXED] What data type should be used with money

 August 11, 2022     database, decimal, mysql, sqldatatypes     No comments   

Issue

I am creating 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.


Solution

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.



Answered By - neurotik
Answer Checked By - Candace Johnson (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing