In the method below, I do ol.price * ol.committed. price is a decimal (40.00)
def self.find_for_order(order)
if order
select("ol.*, p.name as name, (ol.price * ol.committed) as sku_total, p.price as price, p.style_number AS product_style_number, p.name").
from("order_lines ol").
joins("LEFT JOIN skus s ON s.sku_number = ol.style_number").
joins("LEFT JOIN products p ON p.id = s.product_id").
where("ol.order_id = #{order}").
group("ol.id, p.price, product_style_number, name, ol.style_number")
end
end
In my view I have this:
number_to_currency(@order_lines.map(&:sku_total).sum)
This is the result:
$500,400.00
If I run inspect on it I get this:
["500", "400"]
So it thinks they are strings, and just slapping them together instead of adding them. Any ideas how to fix this?
cast the values to numbers.