开发者

How to deal with .1 & .10 with MySQL & Rails

I currently have a MySQL database with a table that has a field that is typed as a decimal.

Currently there are values that range from *.1 through *.9 but we now need to be able to handle the following:

I need to be able to add *.10 to this field and sort it accordingly.

In this use-case .10 DOES NOT equal .1!

I need to be able to use this value in Rails and output it appropriately.


Is there an easy way around this that I am just missing or should I just split it up as fol开发者_运维知识库lows:

Split the one field into two:

2.1 -> 2 & 1

2.10 -> 2 & 10


Thanks in advance!


You either need to split it into two fields or change it to a CHAR field of sufficient length (the two-fields option is probably better from a comparison point of view). A decimal field can't differentiate between 2.1 and 2.10 because they are the same number.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜