I have the following code to identify a decimal number, however if the number is 10. or 10.0 format ie no trailing numbers after decimal point or a single trailing zero my function fails can ay one help?
sub is_float {
#Warning this does not return is_float true when the number ends like:-
# 10. or 10.0 not sure why the decimal point and trailing zero are dropped!
# which then gives variable $_[0] an integer value!!!!
my ($val) = $_[0];
print "Number: $val \n";
return $val=~/\.{1}/;
}
$x = 10.0;
if (is_float($x)){
print "Is A floating point Number\n"}
else {
print "Is not a floating point Number\n"
}
sub is_float {
#Warning this does not return is_float true when the number ends like:-
# 10. or 10.0 not sure why the decimal point and trailing zero are dropped!
# which then gives variable $_[0] an integer value!!!!
my ($val) = $_[0];
print "Number: $val \n";
return $val=~/\.{1}/;
}
$x = 10.0;
if (is_float($x)){
print "Is A floating point Number\n"}
else {
print "Is not a floating point Number\n"
}