MySQL Help - how to store decimal
#1
MySQL Help - how to store decimal
I want to store a decimal number (i.e. 8.5 or 11.4) in a mySQL database but I'm unsure what datatype to use and can't figure it out. Whatever I choose it rounds the figure up.
Can anyone suggest what I need to do?
Chump
Can anyone suggest what I need to do?
Chump
#2
Scooby Regular
Join Date: Jan 2001
Location: Warwickshire
Posts: 2,028
Likes: 0
Received 0 Likes
on
0 Posts
float, double, decimal
FLOAT [(M,D)]
A FLOAT represents small decimal numbers, used when a somewhat more precise representation of a number is required.
ex.
rainfall FLOAT (4,2);
This could be used to represent rainfall average in centimeters per year, which could be a decimal value. More specifically, FLOAT (4,2) states the fact that rainfall can hold up to four characters and two decimal places. Thus,
42.35 is valid, accurately represented.
324.45 is invalid, rounded to 324.5.
2.2 is valid, accurately represented.
34.542 is invalid, rounded to 34.54.
Note: Due to the fact that FLOAT is rounded, those wishing to represent money values would find it wise to use DECIMAL, a datatype found within MySQL that does not round values. Consult the documentation for a complete explanation.
http://dev.mysql.com/tech-resources/...datatypes.html
FLOAT [(M,D)]
A FLOAT represents small decimal numbers, used when a somewhat more precise representation of a number is required.
ex.
rainfall FLOAT (4,2);
This could be used to represent rainfall average in centimeters per year, which could be a decimal value. More specifically, FLOAT (4,2) states the fact that rainfall can hold up to four characters and two decimal places. Thus,
42.35 is valid, accurately represented.
324.45 is invalid, rounded to 324.5.
2.2 is valid, accurately represented.
34.542 is invalid, rounded to 34.54.
Note: Due to the fact that FLOAT is rounded, those wishing to represent money values would find it wise to use DECIMAL, a datatype found within MySQL that does not round values. Consult the documentation for a complete explanation.
http://dev.mysql.com/tech-resources/...datatypes.html
Thread
Thread Starter
Forum
Replies
Last Post
the shreksta
Non Car Related Items For sale
1
19 September 2015 01:39 PM