'This is the variable which I want to express in absolute value .
<%= rate-32.5 =%>
However ,I tried
<%= |rate-32.5 |=%>
It doesn't work .
And I guess there is no this method in ruby .
More generally, the form of the equation for an absolute value function is y=a| x−h |+k.
To solve an equation containing absolute value, isolate the absolute value on one side of the equation. Then set its contents equal to both the positive and negative value of the number on the other side of the equation and solve both equations. Solve | x | + 2 = 5. Isolate the absolute value.
Examples of absolute value expressions or expressions containing one or more absolute value signs, include: |7 - 8 x 4| + 6. 3|6 - 2 x 2| - |-5|
The general form of an absolute value function is f(x)=a|x-h|+k. From this form, we can draw graphs.
Use this link for more details of .abs ruby method.
abs → numeric
Returns the absolute value of num.
12.abs #=> 12
(-34.56).abs #=> 34.56
-34.56.abs #=> 34.56
So you use .abs function for your solution like this
(rate-32.5).abs
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With