homepage Welcome to WebmasterWorld Guest from 54.145.191.14
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / Databases
Forum Library, Charter, Moderator: open

Databases Forum

    
MySQL Datat Type for 1,000 +
Advise anyone?
tongpo

10+ Year Member



 
Msg#: 4531155 posted 5:09 pm on Dec 26, 2012 (gmt 0)

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.

Any sugggestions?

 

LifeinAsia

WebmasterWorld Administrator lifeinasia us a WebmasterWorld Top Contributor of All Time 5+ Year Member



 
Msg#: 4531155 posted 5:27 pm on Dec 26, 2012 (gmt 0)

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.

tongpo

10+ Year Member



 
Msg#: 4531155 posted 5:33 pm on Dec 26, 2012 (gmt 0)

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.

tongpo

10+ Year Member



 
Msg#: 4531155 posted 5:38 pm on Dec 26, 2012 (gmt 0)

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.

LifeinAsia

WebmasterWorld Administrator lifeinasia us a WebmasterWorld Top Contributor of All Time 5+ Year Member



 
Msg#: 4531155 posted 6:04 pm on Dec 26, 2012 (gmt 0)

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

WebmasterWorld Administrator brotherhood_of_lan us a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



 
Msg#: 4531155 posted 6:10 pm on Dec 26, 2012 (gmt 0)

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.

tongpo

10+ Year Member



 
Msg#: 4531155 posted 6:16 pm on Dec 26, 2012 (gmt 0)

Yea thanks, just done that, works as I want now:

$variable = str_replace(',', '', $variable);

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