Notices
Computer & Technology Related Post here for help and discussion of computing and related technology. Internet, TVs, phones, consoles, computers, tablets and any other gadgets.

MySQL Help - how to store decimal

Thread Tools
 
Search this Thread
 
Old 24 September 2004, 11:06 AM
  #1  
chump
Scooby Regular
Thread Starter
 
chump's Avatar
 
Join Date: Feb 2004
Posts: 266
Likes: 0
Received 0 Likes on 0 Posts
Default 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
Old 24 September 2004, 11:16 AM
  #2  
Mickle
Scooby Regular
 
Mickle's Avatar
 
Join Date: Jan 2001
Location: Warwickshire
Posts: 2,028
Likes: 0
Received 0 Likes on 0 Posts
Default

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
Old 24 September 2004, 11:29 AM
  #3  
Dream Weaver
Scooby Regular
 
Dream Weaver's Avatar
 
Join Date: Feb 2000
Location: Lancashire
Posts: 9,844
Received 0 Likes on 0 Posts
Default

Double is also fine for currency, or as above Decimal(10,2), meaning 1111111111.22
Old 24 September 2004, 12:23 PM
  #4  
chump
Scooby Regular
Thread Starter
 
chump's Avatar
 
Join Date: Feb 2004
Posts: 266
Likes: 0
Received 0 Likes on 0 Posts
Default

nice one that fixed it!
Related Topics
Thread
Thread Starter
Forum
Replies
Last Post
KAS35RSTI
Subaru
27
04 November 2021 07:12 PM
alcazar
Non Scooby Related
7
02 October 2015 06:08 PM
Wurzel
Computer & Technology Related
10
28 September 2015 12:28 PM
Littleted
Computer & Technology Related
4
25 September 2015 09:55 PM
the shreksta
Non Car Related Items For sale
1
19 September 2015 01:39 PM



Quick Reply: MySQL Help - how to store decimal



All times are GMT +1. The time now is 02:46 PM.