Welcome to WebmasterWorld Guest from 54.227.110.209

Forum Moderators: open

Message Too Old, No Replies

MySQL data type for small numbers like -11.75?

     

JAB Creations

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

WebmasterWorld Senior Member jab_creations is a WebmasterWorld Top Contributor of All Time 10+ Year Member



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

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

WebmasterWorld Senior Member demaestro is a WebmasterWorld Top Contributor of All Time 10+ Year Member



float shuold work.. have you tried DOUBLE?

JAB Creations

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

WebmasterWorld Senior Member jab_creations is a WebmasterWorld Top Contributor of All Time 10+ Year Member



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

- John

topr8

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

WebmasterWorld Senior Member topr8 is a WebmasterWorld Top Contributor of All Time 10+ Year Member



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

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

WebmasterWorld Senior Member demaestro is a WebmasterWorld Top Contributor of All Time 10+ Year Member



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

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

WebmasterWorld Senior Member jab_creations is a WebmasterWorld Top Contributor of All Time 10+ Year Member



@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

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

WebmasterWorld Senior Member demaestro is a WebmasterWorld Top Contributor of All Time 10+ Year Member



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

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

WebmasterWorld Senior Member jab_creations is a WebmasterWorld Top Contributor of All Time 10+ Year Member



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

- John
 

Featured Threads

Hot Threads This Week

Hot Threads This Month