Connecting Tech Pros Worldwide Help | Site Map

Decimal

 
LinkBack Thread Tools Search this Thread
  #1  
Old October 7th, 2008, 01:56 PM
Newbie
 
Join Date: Oct 2008
Posts: 1
Default Decimal

I want to see if a number is decimal what is the way to do it?
Reply
  #2  
Old October 7th, 2008, 03:29 PM
bvdet's Avatar
Moderator
 
Join Date: Oct 2006
Location: Nashville, TN
Posts: 1,439
Default

Do you mean float?
Expand|Select|Wrap|Line Numbers
  1. >>> num = 1.2345
  2. >>> isinstance(num, float)
  3. True
  4. >>> 
Reply
  #3  
Old October 9th, 2008, 08:18 AM
kudos's Avatar
Expert
 
Join Date: Jul 2006
Location: Norway
Posts: 87
Default

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
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search


Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.