Topic: What's the diffenence between float and decimal?

In Rails'migration,when I create a model,I would like to know the difference between :float and :decimal ?

Many thanks!

I am on rails.

Re: What's the diffenence between float and decimal?

Floats in Ruby are less accurate than Decimals; but only if you were doing something very sensitive. If you are working with currency, I think it best to use Decimal, and then set the precision to 8:

t.decimal :price, :precision => 8, :scale => 2

That'll allow a price of upto 99,999,999.99 (if you're selling anything for 99 million dollars/pounds then let me come and work for you).

Gav

Re: What's the diffenence between float and decimal?

smile GavinLaking ,thank you!It helped me.

I am on rails.

Re: What's the diffenence between float and decimal?

GavinLaking wrote:

Floats in Ruby are less accurate than Decimals; but only if you were doing something very sensitive. If you are working with currency, I think it best to use Decimal, and then set the precision to 8:

t.decimal :price, :precision => 8, :scale => 2

That'll allow a price of upto 99,999,999.99 (if you're selling anything for 99 million dollars/pounds then let me come and work for you).

Gav

Just for clarification, in terms of mysql at least, the precision value is equal to the total number of digits including those after the decimal place. So in the example above a price of 999,999.99 is the maximum allowed value