我希望您专注于conversion = value * 7.50061
请考虑以下事项。当我打印初始值为12的转换时,我会像这样12121212121212
得到7次12。可能那是因为我正在乘以一个字符串,但当我尝试
value.to_i
我发送错误implicit conversion from float to string??
我从视图中的输入元素提交一个值,然后将其从CalculationsController
输入到CalculationsHelper
module CalculationsHelper
# parameter1 = Sa02, parameter2 = Hgb, parameter3 = PaO2
def AOC(parameter1,parameter2,parameter3,unit_parameter2,unit_parameter3)
# CaO2 = ( Hgb * 1.34 * SaO2 / 100 ) + ( PaO2 * 0.031 )
if (unit_parameter3 != "mmHg")
puts "entered conversions"
conversions(unit_parameter3,parameter3, "mmHg")
end
end
def conversions(input, value, target)
if (target == "mmHg")
if (input == "Kpa")
puts "this is the value before " + value
conversion = value * 7.50061
puts "this is the " + conversion
end
end
end
end
CalculationsController
class CalculationsController < ApplicationController
include CalculationsHelper
def index
end
def calculation
if (params["equation"] == "AOC")
puts "entered AOC"
AOC(params["parameter1"],params["parameter2"],params["parameter3"],params["unit_parameter2"],params["unit_parameter3"])
end
respond_to do |format|
format.json {
render json: { success: "ok" }
}
end
end
end
任何帮助表示赞赏
答案 0 :(得分:1)
你走在正确的轨道上,首先需要将字符串value
转换为浮点数或整数来进行计算。如果String是12
,将它转换为整数可能更有意义:
conversion = value.to_i * 7.50061
您在下一行(implicit conversion from float to string
)中收到"this is the " + conversion
错误,因为您尝试向字符串添加浮点数。
改为写:
puts "this is the #{conversion}"
答案 1 :(得分:0)
.EntireRow.Delete