Connecting Tech Pros Worldwide Help | Site Map

Decimal

Newbie
 
Join Date: Oct 2008
Posts: 1
#1: Oct 7 '08
I want to see if a number is decimal what is the way to do it?
bvdet's Avatar
Moderator
 
Join Date: Oct 2006
Location: Nashville, TN
Posts: 1,560
#2: Oct 7 '08

re: Decimal


Do you mean float?
Expand|Select|Wrap|Line Numbers
  1. >>> num = 1.2345
  2. >>> isinstance(num, float)
  3. True
  4. >>> 
kudos's Avatar
Expert
 
Join Date: Jul 2006
Location: Norway
Posts: 109
#3: Oct 9 '08

re: Decimal


I guess you could do the following test:

Expand|Select|Wrap|Line Numbers
  1. a = 1.23
  2. if(a%1 == 0):
  3.  print "integer"
  4. else:
  5.  print "float"
  6.  
Would ofcourse fail for 1.0 etc, but then I guess it doesn't matter if its float

-kudos
Reply