Page 1 of 1
What Type is best for long decimal number in SQL database?
Posted: Fri Mar 30, 2012 7:40 pm
by Verahta
I need to have numbers with values like this in my database (using SQL/MySQL/PHPmyAdmin): 4785.556448294
For type (int/float/decimal/double), which one is the best for this kind of number value?
Thank you ol wise ones!!!

Re: What Type is best for long decimal number in SQL databas
Posted: Fri Mar 30, 2012 8:08 pm
by Nexus
Re: What Type is best for long decimal number in SQL databas
Posted: Sat Mar 31, 2012 11:21 am
by Verahta
http://dev.mysql.com/doc/refman/5.5/en/ ... types.html
Turns out the Float Type wont work for me, it does approximate values and rounds. I need to store exact, set numbers. But, the numbers like the one I posted in my OP, is created by combining two difference values (one before and after the decimal). Now, it occurred to me, that the number on the right will always be unique, but the number on the left can be repeated many times by other number combinations.
So like this: 4785.556448294
4785 = a value on left side of decimal that could be repeated in combination with many unique values on right side of the decimal.
. = the decimal that both separates AND combines the number into a unique total value.
556448294 = a value that is unique to a single database entity only. But which could have several different values on left side of decimal. Like 1275.556448294 or 3496.556448294, and then each of 1275 and 3496 could some time be on left side of many unique future numbers/entities in the DB.
So now I'm thinking instead what I should do, is have two different tables, with primary keys for each set of numbers, then a third table to combine/match numbers and create the entire number sequence (like with repeating number's id in one column, and unique numbers id in other column)... then how to combine it? I guess I need to figure out if I want the numbers to exist only separately in the database and then only be "combined/made whole" when PHP echos to the page, or do I want to have a 3rd/4th table that stores the combos in entirety as another entity?
Re: What Type is best for long decimal number in SQL databas
Posted: Sun Apr 01, 2012 12:30 am
by fang
Or you could just store exact values in strings (VARCHAR perhaps) and simplify the problem (convert application-side).
Re: What Type is best for long decimal number in SQL databas
Posted: Sun Apr 01, 2012 5:09 am
by Callan S.
if you know how many digits long the number is, you could multiply it to make a really, really large number and store that. Then when you get it back, divide it to make it back to a fraction
ie
4785.556448294
becomes
4785556448294
Re: What Type is best for long decimal number in SQL databas
Posted: Sun Apr 01, 2012 5:37 pm
by Verahta
Okay I will try both ways, thanks for the suggestions guys.