哪种整数数据类型的作用域大于rails中的整数?

时间:2019-06-04 10:40:17

标签: ruby-on-rails database-migration

我使用字段:price初始化了一个模型。此字段中的值的最小值为一百万,我不知道要在迁移文件中使用哪种数据。

class CreateTours < ActiveRecord::Migration[5.2]
  def change
    create_table :tours do |t|
      t.references :detail, foreign_key: true
      t.integer :price
      t.datetime :start_date
      t.integer :tour_quantity

      t.timestamps
    end
  end
end

1 个答案:

答案 0 :(得分:0)

您可以在ruby命令行中尝试这些命令,并观察输出。它不仅可以处理百万,而且可以处理十亿。

puts 1_000_000_000_000_000_000_000_000_000_000_000.instance_of? Fixnum
puts 1_000_000_000_000_000_000_000_000_000_000_000.instance_of? Bignum
puts 1_000_000_000_000_000_000_000_000_000_000_000.instance_of? Integer 

从Ruby 2.5.0开始,它将返回 弃用, 弃用, 是

是的, Bignum Fixnum 现在被合并为一种类型的 Integer