There is no way to change this in the API, it handles only micros
(exception are reports, they return normal currencies in their CSV or
XML).

Your undefined 'to_f' method exception gets thrown because
'campaign.budget.amount' is a Money object and not a number.
To get the microAmount, you should call
'campaign.budget.amount.microAmount' and divide it by 1000000.0.
So, to give you an example:

#campaign_controller
#dividing by a float makes the number a float
campaign_data.budget = campaign.budget.amount.microAmount / 1000000.0

#campaign view
#the sprintf method makes the number a float with 2 decimals and
returns it as a string
<p>campaign budget: $ <%= sprintf("%.2f", campaign_data.budget) -%></
p>

I hope this helps!

Regards,

Wilrik
050media

On Oct 14, 7:35 pm, Bowles <[email protected]> wrote:
> Here is the general set up in app/controller/campaigns
> ==============
>  if response and response.rval and response.rval.entries
>       campaigns = response.rval.entries
>       campaigns.each do |campaign|
>         campaign_data =
> Campaign.find_or_initialize_by_campaign_id(campaign.id)
>
>         campaign_data.campaign_id         = campaign.id.to_i
>         campaign_data.name                = campaign.name
>         campaign_data.budget              = campaign.budget.amount
>         #campaign_data.impression_share   =
>         #campaign_data.quality_lost_share =
>
>         campaign_data.status              = campaign.status
>         campaign_data.clicks              =
> campaign.campaignStats.clicks
>         campaign_data.impressions         =
> campaign.campaignStats.impressions
>         campaign_data.click_through_rate  = campaign.campaignStats.ctr
>         campaign_data.cost_per_click      =
> campaign.campaignStats.averageCpc
>         campaign_data.cost                =
> campaign.campaignStats.cost
>         campaign_data.bid_position        =
> campaign.campaignStats.averagePosition
>         campaign_data.leads               =
> campaign.campaignStats.conversions
>         campaign_data.cost_per_lead       =
> campaign.campaignStats.costPerConversion
>         campaign_data.conversion_rate     =
> campaign.campaignStats.conversionRate
> =================================================================
>
> Specifically, if I have
>
>               "  campaign_data.budget              =
> campaign.budget.amount "
>
> in app/views/campaigns/index.html.erb
>               "  <td><%=h number_to_currency(campaign.budget) %>/day</
> td>  "
> for the table. Fro calling the method in my views i have
>               "  <%= link_to "load campaigns",
> get_campaigns_campaigns_path(:campaign_id => 0)  %>  "
>
> The problem is that it seems like the micro/millions format is default
> and I can't figure out how to change it via the API.
>
> For example if
>                  "   campaign_data.budget              =
> campaign.budget.amount.to_f   "
> I get exception
>                  "  undefined method `to_f' for
> #<AdWords::V201008::CampaignService::Money:0x104ee95f8   "
>
> Same error with ".to_d". If I try ".to_s" or append nothing to
> "campaign.budget.amount" I still get millions.
>
> On Oct 14, 7:44 am, Wilrik Mook <[email protected]> wrote:
>
>
>
> > Hello,
>
> > I suppose you are using the Ruby client library (adwords4r)?
> > Your problem probably has to with the fact that a Budget contains
> > Money, in which the microAmount is defined as one million units for
> > one unit of your local currency.
> > So 1,000,000 microAmount units  would represent $1. 
> > Seehttp://code.google.com/apis/adwords/docs/reference/latest/CampaignSer...
> > andhttp://code.google.com/apis/adwords/docs/reference/latest/CampaignSer....
>
> > For further help, could you provide a code sample where you are
> > setting the budget of the campaign? Then it might be easier to find
> > the problem.
>
> > Regards,
>
> > Wilrik
> > 050media
>
> > On Oct 14, 12:16 am, Bowles <[email protected]> wrote:
>
> > > first pass at updating campaign info; budget updates with 5 extra
> > > digits; what should be $2,500.00 is $250,000,000.00.
>
> > > "campaign.budget.amount" raises error about .to_f not defined; also
> > > error if I add .to_f; works but same format errors with .to_s.
>
> > > "campaign.budget.amount.microAmount" gives the right format but wrong
> > > values (i.e., 0.00), appending .to_f leaves me with the same format
> > > errors.
>
> > > Any suggestions?

-- 
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog and discussion group:
http://adwordsapi.blogspot.com
http://groups.google.com/group/adwords-api
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~

You received this message because you are subscribed to the Google
Groups "AdWords API Forum" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/adwords-api?hl=en

Reply via email to