Ruby on Rails: Failing to convert value in hash to float
I feel like I'm missing something really obvious here.
I have the following hash placed in variable "simple_lable". Calling
inspect on it works fine, but I cannot seem to access any of the numerical
values. .to_i comes out as 0, .to_f comes out as 0.0 and to_s comes out
blank
puts "**************************"
puts simple_label.inspect
puts simple_label["margin_top"].to_f
puts simple_label["margin_bottom"].to_f
puts simple_label["margin_right"].to_f
puts simple_label["margin_left"].to_f
puts simple_label["paper_size"]
puts "**************************"
results in
**************************
{"paper_size"=>"LETTER", "top_margin"=>36, "bottom_margin"=>36,
"left_margin"=>15.822, "right_margin"=>15.822, "columns"=>3, "rows"=>10,
"column_gutter"=>15, "row_gutter"=>0}
0.0
0.0
0.0
0.0
LETTER
**************************
So the values are there, but I just can't seem to get hold of them correctly.
Any ideas?
Many thanks.
No comments:
Post a Comment