Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I convert boolean values to integers?

Tags:

ruby

boolean

I have a boolean value to check if it is true, then set a local variable. How do I refactor this so it is more Ruby-ish?

if firm.inflection_point   inflection_point = 1 else   inflection_point = 0 end 
like image 203
marcamillion Avatar asked Nov 24 '12 00:11

marcamillion


People also ask

Can you cast a boolean to an int?

Using the method booleanObjectMethodToInt, we can convert a boolean value to an integer the same way we did with the static method.

What integer value is true boolean value converted to?

If the Boolean value is true , the result is an int with a value of 1. If the scalar value is equal to 0, the Boolean value is 0; otherwise the Boolean value is 1.

How do you cast boolean to int in Python?

Python convert boolean to integer To convert boolean to integer in python, we will use int(bool) and then it will be converted to integer.

How do you convert boolean?

To convert Boolean to String in Java, use the toString() method. For this, firstly, we have declared two booleans. String str1 = new Boolean(bool1). toString(); String str2 = new Boolean(bool2).


1 Answers

inflection_point = (firm.inflection_point ? 1 : 0) 
like image 137
rudolph9 Avatar answered Sep 19 '22 03:09

rudolph9