My RoR is currently giving me some problems for Bigdecimal records.
my code is to update certain attribute with:
BigDecimal.new((income*scale).to_s)
For example there is a form that I scanned and its value is
11210000000.0
when i print the bigdecimal it looks like:
#<BigDecimal:91e2284,'0.1121E11',18(27)>
when i look the record in mySQL db the record appears with
Income: 9999999999
all the records with income less than 10 billion do not have this problem.
What is going on?
I think (because I can't find it in the docs but I know it's the case for Integer) that BigDecimal has no MAX value in Ruby. Unfortunately all database systems have those limits so you may wish to store big numbers as strings in the database.
wrote this in the terminal:
rails g migration change_income_format_in_my_table
then set the migration file as:
class ChangeIncomeFormatInMyTable < ActiveRecord::Migration
def up
change_table :forms do |t|
t.change :income, :decimal, :precision => 16, :scale => 2
end
end
def down
change_table :forms do |t|
t.change :income, :decimal
end
end
end
then typed
rake db:migrate
thanks house9
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.