Gmail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
Decimals are being converted to Bigdecimals!!!!!
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  2 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Neal L  
View profile  
 More options Jan 19 2008, 12:09 pm
From: Neal L <neal.lo...@gmail.com>
Date: Sat, 19 Jan 2008 09:09:50 -0800 (PST)
Local: Sat, Jan 19 2008 12:09 pm
Subject: Decimals are being converted to Bigdecimals!!!!!
Hi all,

I'm working on a financial app, and have set up some columns in my
tables as decimals with precision => 8 and scale => 2.  My migration
looks like:

    change_column :lineitems, :price, :decimal, :precision =>
8, :scale => 2
    change_column :payments, :amount, :decimal, :precision =>
8, :scale => 2

I've run the migration and restarted the server. I also looked at the
Mysql tables to verify that the migration ran correctly, and the
fields look like they're set up right ( DECIMAL(8,2) ).

The problem is that when I access these columns in the console, they
show up as Bigdecimal and it's messing up my calculations.  Here's
what it looks like from the rails console:

>> Lineitem.find(34).price

=> #<BigDecimal:31e4c74,'0.3E4',4(12)>
>> Payment.find(23).amount

=> #<BigDecimal:31b8480,'0.4125E4',4(12)>

What's going on here?  How do I get Rails to recognize that these are
decimal/currency amounts?????


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Rick DeNatale  
View profile  
 More options Jan 19 2008, 3:08 pm
From: "Rick DeNatale" <rick.denat...@gmail.com>
Date: Sat, 19 Jan 2008 15:08:44 -0500
Local: Sat, Jan 19 2008 3:08 pm
Subject: Re: [Rails] Decimals are being converted to Bigdecimals!!!!!
On 1/19/08, Neal L <neal.lo...@gmail.com> wrote:

BigDecimal is just the Ruby class which represents decimal fixed point numbers.

How is it "messing up your calculations?"

>> b = BigDecimal.new("100", 2)

=> #<BigDecimal:13f4e6c,'0.1E3',4(8)>
>> b.to_s
=> "100.0"
>> b + 1

=> #<BigDecimal:13f0b8c,'0.101E3',4(12)>
>> (b + 1).to_s

=> "101.0"

--
Rick DeNatale

My blog on Ruby
http://talklikeaduck.denhaven2.com/


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google