Perl Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPerl Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old April 6th, 2001, 12:39 AM
Asil Asil is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2001
Posts: 0 Asil User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
How would you go about determining if a number is an integer or a float?

Reply With Quote
  #2  
Old April 6th, 2001, 03:40 AM
gareth_heyes gareth_heyes is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2001
Posts: 14 gareth_heyes User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
$number = 1.2334;
if($number =~ /\./)
{
print "This is a floating point number.";
}
else
{
print "This is a integer.";
}

Reply With Quote
  #3  
Old April 6th, 2001, 10:32 AM
unobserved unobserved is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2001
Posts: 11 unobserved User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to unobserved
gareth, the only problem with that is that it will fail with a number like 3.0 which you might want interpreted as an integer.

i would suggest using this code

Code:
my $num = 3.1254;
if($num - int($num)) { print "is float"; }
else { print "is integer"; }

Reply With Quote
  #4  
Old April 7th, 2001, 10:58 PM
Asil Asil is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2001
Posts: 0 Asil User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Awesome
Thanks a bunch!

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPerl Programming > Determining Ints


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway