| Welcome to WebmasterWorld Guest from 220.127.116.11 |
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
|Pubcon Platinum Sponsor 2014|
|MySQL Datat Type for 1,000 +|
Which numeric datatype can I use to store numbers with a comma for thousandth seperator.
Interger etc dont accept it, when I use varchar and sort the rows asc/des this doesent work either.
If you want to sort the numbers, you'll need to use a numeric type (int, etc.). Use the Format() function to format the numbers with commas when displaying them.
THe numbers in question come from a third party source already formatted with thousandths as 1,200 etc. So its not a question really of inputting them as 1200 and displaying them with commas.
I just want to be able to input them as I receive them i.e 1,300 into database and then be able to sort them by asc/desc correctly which obviously storing them as varchar does not do.
And int etc does not insert them correctly, I guess Im just going to have to alter them before insertion so 1,200 becomes 1200.
You'll need to either:
A) Strip the commas when you import them as INT, or
B) Import them as VARCHAR then strip the commas and save into a different field (type INT).
|brotherhood of LAN|
|A) Strip the commas when you import them as INT, or |
I'd go for LifeinAsia's A) suggestion, as it's trivial to replace the commas while performing operations on a smaller and fixed length field has its advantages.
Yea thanks, just done that, works as I want now:
$variable = str_replace(',', '', $variable);
All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved