This is in the Perl FAQ, follow link below.
In perl, how can i find whether or not an input is a number or interger?
I have never user perl but judging from other programmign languages, you should be able to see how many digits long the number is, and if the number is %26lt;= 10 and longer than 1 digit then it is a decimal. Do this for 1- however many digits long u plan on the number getting.
Reply:You'd use a piece of code that checks if the rounded version is equal to the orginal value. If it is then it's an interger:
if( $num == sprintf("%.0f", $num) )
{
...
}
This uses the sprintf function. %.0f = no numbers after the decimal point
printable cards
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment