homepage Welcome to WebmasterWorld Guest from 54.211.235.255
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / Databases
Forum Library, Charter, Moderator: open

Databases Forum

    
MySQL data type for small numbers like -11.75?
JAB Creations




msg:4088116
 10:47 pm on Feb 26, 2010 (gmt 0)

What would be the most desirable MySQL data type for small numbers like -11.75? Every type (int, float, decimal) I've tried resets the number to -12.

- John

 

Demaestro




msg:4088117
 10:52 pm on Feb 26, 2010 (gmt 0)

float shuold work.. have you tried DOUBLE?

JAB Creations




msg:4088123
 11:03 pm on Feb 26, 2010 (gmt 0)

Neither double nor float worked and both reset the number to -12.

- John

topr8




msg:4088127
 11:10 pm on Feb 26, 2010 (gmt 0)

obviously you tried setting it as DOUBLE(4,2)

which is what i use to store small currency amounts with 2 decimal places, works for me although i don't have negatives

Demaestro




msg:4088135
 11:22 pm on Feb 26, 2010 (gmt 0)

hmm... If you specify that it is UNSIGNED that it will disallow negatives according to MySQL's docs. I wonder if that is your issue.

You can also try DECIMAL.

Make sure when you define the data type you passing 2 values.

DOUBLE(M,D)

If M and D are omitted, values are stored to the limits allowed by the hardware, M is the total number of digits and D is the number of digits following the decimal point. It could be your hardware limit is low if you didn't specify these values.

JAB Creations




msg:4088136
 11:31 pm on Feb 26, 2010 (gmt 0)

@topr8 Not obvious if it's my first time working with non-whole numbers.

Apparently floats are intended for smaller numbers and doubles for larger numbers according to a site that comes up for the search, 'MySQL data types'.

Turns out after testing the length of a value that what I wanted was float(4,2) which I'm using to store time zone unless any one has a better suggestion for that?

Thanks for your replies! :)

- John

Demaestro




msg:4088145
 11:37 pm on Feb 26, 2010 (gmt 0)

That is what I would use... glad you got it working, just make sure the values won't go higher than 9999.99 as anything higher or lower won't fit.

JAB Creations




msg:4088155
 11:49 pm on Feb 26, 2010 (gmt 0)

Well unless the world's rotation drastically slows in our lifetime I think this will work just fine. :)

- John

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Databases
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved