search for: to_f

Displaying 20 results from an estimated 91 matches for "to_f".

Did you mean: to_a
2007 Feb 02
0
Fwd: [ mocha-Bugs-7834 ] infinte_range.rb makes incorrect assumption about to_f
Thanks for reporting the bug below. You''re absolutely right. Renamed Range#to_s implementation to #mocha_inspect and checked first and last respond_to?(:to_f) as you suggested. Sorry for the delay - I wasn''t monitoring the rubyforge trackers. I am now! Should be fixed in revision 99 of trunk. -- James. http://blog.floehopper.org ---------- Forwarded message ---------- From: noreply at rubyforge.org <noreply at rubyforge.org> Date: 02...
2005 Dec 15
8
slightly OT - Ruby division
Hey all, In my code, it seems that when I divide two integers, the result is an integer. Is there any way to make it such that when I divide two integers, the result is a double? Any help appreciated, Jin _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
2005 Oct 28
4
find_by_sql column types
...e return @@domain_average else @@domain_average = MyDomain.find_by_sql(["select avg(latency) as latency, avg(datediff(session_end, session_start)) as session_duration from live_logs where domain_id=?"], domain_id])[0] end end The problem is that I¹m using a lot of to_f conversions because type coercions are not happening as I would have expected. Again, for example: foo = MyDomain.find_averages(1) bar = foo[:latency] / 3.0 # fails because foo[:latency] is a string and Ruby won¹t do the coercion zoo = foo[:latency].to_f / 3.0 # succeeds because I did the...
2006 Sep 13
4
Mini_Magick Problem
I can''t for the life of me figure this out. Been banging my head on this since the weekend, and can''t see what I''m doing wrong. This code works: image.resize("640x480") image.write(path) I run this and I get the resized file just fine. This doesnt work at all: width = 200 height = 100 dimensions = "#{width}x#{height}"
2011 Feb 09
4
Modules being shared and model data
Have in a module in ./lib: module Pricing def sell_price (cost.to_f)/((100-(margn.to_f))/100) end def sell_price_inc ((product.cost.to_f)/((100-(product.margn.to_f))/100)*1.14) end def charge_excl (sell_price).to_f * quantity end end A model product: class Product < ActiveRecord::Base include Pricing attr_accessible :name, :code, :cost,...
2006 Mar 21
13
Double and single quote usage in AWDWR
Hello everyone! I''ve noticed, that the book uses double quotes almost everywhere. It is like <%= javascript_include_tag "prototype" %> I''ve checked the "programming ruby, 2ed" book and found that double quotes are most suited when escape sequences and substitutions are required. Isn''t it more semantically correct to write this code like
2006 Sep 25
3
Engine Yard blog
Just received the news from Tom Mornini. Congrats Ezra for the new Engine Yard site and the blog you will be collaborating. Hope to read you there soon. http://www.engineyard.com/ Jonathan -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/backgroundrb-devel/attachments/20060925/3f251fa4/attachment.html
2008 Mar 20
0
Having trouble with a remote-crop-then-resize using attachment fu =(
...reated, :location => @ying } else format.html { render :action => "new" } format.xml { render :xml => @ying.errors, :status => :unprocessable_entity } end end end YING.rb def scale_to_scene(params, scene) x1 = params[:x1].to_f*scene.wscale.to_f y1 = params[:y1].to_i*scene.hscale.to_f width = params[:width].to_f*scene.wscale.to_f height = params[:height].to_f*scene.hscale.to_f img = Magick::Image.read("#{RAILS_ROOT}/ public#{scene.avatar.public_filename}")[0] chopped = img.crop(Magick::ForgetGravity, x...
2008 Mar 14
0
problem with rjs and marker group
...i @zoom = 14 if params[:zoom].nil? @map = GMap.new("map_div") # @map.control_init(:large_map => true, :map_type => true) # (inserts map control) # place the map where we want it ( center and zoom level ) @map.center_zoom_init([@group.group_map_stat.lat.to_f, @group.group_map_stat.long.to_f], @zoom) @map.set_map_type_init(GMapType::G_HYBRID_MAP) @sites = @group.sites @sites.each do |site| # draw the circles site.map_stat.circle_image(@zoom) end @all_markers = make_map_markers(@sites, @zoom) @map.overl...
2006 Jun 23
6
float calculation error
Hi I have the following values pActualCost = 33.00 pPaymentCost = 29.99 So this calculation should leave me with 0.01 pPaymentDifference = pActualCost - pPaymentCost however when doing this in rails, it returns 0.00999999999999801 has anyone got any suggestions to whats going wrong and how I can correct this Thanks Scott -- Posted via http://www.ruby-forum.com/.
2006 Sep 20
3
Range searches some times they work, some times not...
...g me that all the test data is with 8 metres of the origin... thanks in advance. clare if their_outcode && their_outcode.size > 0 temp_hwz = HwzPostcode.find(:first, :conditions => [''outcode = ?'',their_outcode]) range_x_left = temp_hwz.x - (postcode_distance.to_f*1.60934 * 1000) range_x_right = temp_hwz.x + (postcode_distance.to_f*1.60934 * 1000) range_y_top = temp_hwz.y + (postcode_distance.to_f*1.60934 * 1000) range_y_bottom = temp_hwz.y - (postcode_distance.to_f*1.60934 * 1000) query += " AND x:[#{range_x_left.to_i} #{range_x_right.to_i}]...
2009 Feb 09
3
RSpec Testing ActiveRecord config dependency.
I have the following library code: def normal_time_now return DateTime.now.utc if default_timezone == :utc return DateTime.now end This is dependent upon a setting in config/environment.rb # Make Active Record use UTC-base instead of local time config.active_record.default_timezone = :utc I want to test that I get the expected results with the config set to utc and
2005 Oct 17
8
Using active record for SELECT MAX(column) FROM ...
Hi, Is there an easy way of querying an active record for a maximum column value? I need to do queries like: SELECT MAX(salary) FROM employees TIA, Jeroen
2006 Jun 28
3
how do I validate currency format if I am storing in cents?
Hi all - To avoid floating point issues, I''ve decided to store monetary values in cents in the database. However, the user will enter these in dollars and cents. Two questions: 1) How do I do the validation for the currency format? It looks like ActiveRecord truncates the cents since it thinks the field type is a Fixnum. Am I forced to do validation in the controller? 2) Where
2006 Jul 19
5
Model Validation - with a twist
...ot = doc.root retstatus = root.elements[''/kml/Response/Status/code''].text if retstatus.to_i == 200 coordinates = root.elements[''/kml/Response/Placemark/Point/coordinates''].text long1, lat1, = coordinates.split('','').map { |v| v.to_f } params[:bookstore][:latitude] = lat1 params[:bookstore][:longitude] = long1 @bookstore = Bookstore.new(params[:bookstore]) if @bookstore.save redirect_to :action => ''add'' flash[:notice] = ''Store was successfully added.''...
2008 Jul 23
3
Validation method vs. After Save & Rollback
...ompany.total_share # => This is summing the old value if changed? if changes["share"] # => Changes to a model are stored in the changes array on the instance, the array has 2 value ["from_value", "to_value"] old_value = changes["share"][0].to_f # => Convert To Float new_value = changes["share"][1].to_f new_total_share = company_total_share - old_value + new_value new_total_share > 100.01 else false # validation succeeds end else false # validation succeeds end end It is worki...
2006 Nov 04
0
RJS not setting form input value correctly
...value=''" + number_to_currency(@new_total_commission, { :precision => 4 }).to_s + "'';" The controller code is as follows in the update_totals method which is called via the observe_field : if @comm_type == "L" @new_total_commission = @new_total_sell.to_f * @converted_rate.to_f else @new_total_commission = @new_total_weight.to_f * @converted_rate.to_f end Outputting debug to the log file shows that the @new_total_commission is being set correctly. The debug information in the browser window for the RJS "trick" produces the following:...
2008 Oct 29
0
RJS problem after upgrading to Rails 2.0.2
...end def price_override if request.post? @type = params[:type] @price = params[:price] @index = params[:index] unless params[:price].blank? if params[:type] == ''lineitem'' session[:lineitems][params[:index].to_i][1] = params[:price].to_f unless session[:lineitems].nil? elsif params[:type] == ''contract'' session[:contract_lines][params[:index].to_i][5] = params[:price].to_f unless session[:contract_lines].nil? else flash[:error] = "There was a problem completing your request,...
2008 Mar 19
2
ActiveRecord bug? ActiveRecord::ConnectionAdapters::Column.type_cast for float columns
Hi all, I just noticed that in ActiveRecord::ConnectionAdapters::Column.type_cast[1] (and type_cast_code[2]) the type casting for float columns simply does value.to_f, whereas all the others have a rescue or call out to a method, the default implementations of which have rescues or enough logic in that I don''t think they''d fail. Imagine the following: create_table :vehicle do |t| Now, doing some archaeology on trac, I''ve found that...
2006 Apr 02
16
12 / 16 = 0
Hi, Just thought it was weird that Ruby doesn''t automatically cast ints to floats. Seems so un-rubyish irb(main):006:0> 12/16 => 0 irb(main):007:0> 12.to_f / 16.to_f => 0.75 Jeroen