Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4099258
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T20:24:38+00:00 2026-05-20T20:24:38+00:00

I’ve got a strange problem which I just can’t figure out. I have currencies

  • 0

I’ve got a strange problem which I just can’t figure out. I have currencies stored in my database as a decimal. I am reading from a CSV file and converting the string to a decimal to store in the database. The values don’t seem to be stored correctly when inspecting the database, most are stored correctly but for some reason a value of 1000 that I have is stored as 1 and 2299 is stored as 2 so there are obviously problems with numbers over 999.99

I ran a database migration as follows:

def self.up
change_column(:transactions, :in, :decimal, :precision => 8, :scale => 2 )
change_column(:transactions, :out, :decimal, :precision => 8, :scale => 2)
end

Here is the code used to store the value from the CSV file:

def create

data = params[:dump][:file].read

FasterCSV.parse(data, :headers => true) do |row|

  transaction = Transaction.new
  transaction.date = Date.strptime(row[0], "%d/%m/%Y")
  transaction.transaction_type = row[4]
  transaction.details = row[3]

  if row[7].to_f < 0
    transaction.out = row[7].to_d.abs
  else
    transaction.in = row[7].to_d.abs
  end
  transaction.save

(The .abs is because money out values are just stored as negative values in the CSV file).

When I use the console to create a new transaction and convert a string of 1000 and store it using the same method however then this works fine and the value is stored as 1000.0.

Does anybody have any idea why this would be? I wouldn’t have though this is a FasterCSV issue but I suppose it’s possible if the CSV numbers are not being read properly.

Thanks for any help,

Tom

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T20:24:39+00:00Added an answer on May 20, 2026 at 8:24 pm

    Have you looked at the raw CSV data for a row with a value >= 1000? It sounds to me like the data is formatted with commas every 3 digits, and the to_d method will ignore everything after the first comma in that case.

    >> '1,123.41'.to_d
    => #<BigDecimal:10593e0a8,'0.1E1',9(18)>
    

    If that’s the problem, just strip the commas using gsub.

    >> '1,123.41'.gsub(',','').to_d
    => #<BigDecimal:105932398,'0.112341E4',18(18)>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
I have a jquery bug and I've been looking for hours now, I can't
I have an autohotkey script which looks up a word in a bilingual dictionary
I have an array which has BIG numbers and small numbers in it. I
I have a text area in my form which accepts all possible characters from
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have been unable to fix a problem with Java Unicode and encoding. The
I have a view passing on information from a database: def serve_article(request, id): served_article
I have a reasonable size flat file database of text documents mostly saved in
I have a bunch of posts stored in text files formatted in yaml/textile (from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.