简体   繁体   中英

Varchar or decimal and cast

I've a table filled with products. Some of their characteristics like width and height are decimal. Until now, we were using floats but there was some problems with select not working, like:

 SELECT ... WHERE width = 3.4 

was giving no results, while

SELECT ... WHERE width LIKE "3.4%" 

was.

So I'm looking to change column's type and I've the choice between varchar and decimal. I don't want any trailing zeroes on my frontend so if I go for decimal type, I'll have to change all my models to cast characteristics as char and then removing zeroes which could induce a lot of bugs.

What's the best type to choose knowing that I don't have any calculations to do on those characteristics and I only have to select with equalities, no greater than / less than.

Thanks for any help.

EDIT:

I tried to change columns' type to decimal, and casting to char to removing trailing zeroes take too much time, from 25ms to 500ms. I guess I've no other choice but removing them with php :(

Using varchar will probably give you more work compared to using decimals , and also varchar might make your variables lose precision when casting . so i suggest sticking with decimals

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM