Friday, November 13, 2009

Perl: What is the equivalent to floor()

Question: What is the equivalent of function floor() at Perl?

Answer: Simple answer is to use int() function. This will just remove the decimal portion from the provided number. Example code using int() to serve like floor is,

print int(10.9);

1 comment:

Anonymous said...

This is incorrect. the int function will remove the floating point portion of the number which is not the same as the floor function, as the floor function will always round down to the next whole integer. while they will give the same result for positive numbers (int(2.7) = 2 and floor(2.7) = 2) they will give different results for negative numbers. int(-2.7) = -2, but floor(-2.7) = -3.

Get function name programaticaly - Python

This little piece of code will help you to get the function name programatically. This is very helpful when you are implementing the debug...