【问题标题】:What integer data type has a scope greater than integer in rails? [duplicate]什么整数数据类型的范围大于 Rails 中的整数? [复制]
【发布时间】:2019-10-19 21:17:48
【问题描述】:

我用字段: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

【问题讨论】:

    标签: ruby-on-rails database-migration


    【解决方案1】:

    您可以在 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 开始,它将返回 弃用, 弃用, 是的

    是的,BignumFixnum 现在合并为一种类型 Integer

    【讨论】:

    • 感谢您回答我的问题。
    猜你喜欢
    • 1970-01-01
    • 2012-11-16
    • 1970-01-01
    • 1970-01-01
    • 2011-11-30
    • 1970-01-01
    • 2012-03-03
    • 2013-09-20
    • 2013-10-11
    相关资源
    最近更新 更多