if (do_name() != 'Home') : ?>
endif ?>
Posted by Tom De Smedt on Jul 23, 2009
You could also divide 43 by 359.0 - then 43 will be cast to a float because you can't divide an integer by a float.
You can also do this by using the float() function in Python:
To elaborate on this, you need to multiply by 1.0, not just 1.
print 1 * 43 / 359 # yields 0 print 1.0 * 43 / 359 # yields 0.119777158774Python has no explicit data types, it will just use whatever is appropriate. So if you start with a float (1.0) and multiply it with 43, you still have a float.
You could also divide 43 by 359.0 - then 43 will be cast to a float because you can't divide an integer by a float.
You can also do this by using the float() function in Python:
print float(43) / 359 # yields 0.119777158774There's also an int() function:
print int(1.0) # yields 1 print int("1") # yields 1To check what kind of data is stored in a variable, you can use Python's isinstance() function:
print isinstance(43, int) # yields True print isinstance(43, float) # yields False print isinstance("a", str) # yields True
Posted by _brentonW on Jul 23, 2009
include("util/comment.php"); ?>
Tom - thanks for the clarification and additional information. Very helpful.
normalizing a number
Posted by _brentonW on Jul 23, 2009I'm posting this here because I have been searching nodebox for information on generating floating point and integer numbers and have been unsuccessful. I have solved my problem. Hope it helps others. If there are other approaches to this problem please add your info.
Note: You must multiply the number to be converted by 1 in order for a floating point number to be returned.Problem:
Want to convert a photoshop hue (degrees) into a usable nodebox normalized 0.0 to 1.0 system for colormode(HSB).
Solution:
Create a function that takes your number to be converted, multiplies it by 1 important, and divides by Photoshop's number system (0 to 359 degrees).
Example:
hue*1.0/359
I would love for someone to explain why. This is different from Processing which requires a data type identifier.
Hope this is helpful to others.