I can't get a floating point number to calculate in a simple progr

Page 1 of 1

2 Replies - 488 Views - Last Post: 22 March 2013 - 01:50 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=316356&amp;s=432c2cce8d7cfdbf8e1e266ba57e15c7&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

#1 pidgeonpancakes

• New D.I.C Head

Reputation: 0
• Posts: 19
• Joined: 10-August 11

I can't get a floating point number to calculate in a simple progr

Posted 22 March 2013 - 01:25 PM

I'm trying to learn Python on my own and I'm doing little projects to learn the nuances of the language. In the simple script below I'm trying to take a radius of a circle as input from a user and print out the circumference of the circle. It always rounds to a whole number though and I can't figure out why. Can someone give me some hints or point me in the right direction as to why? I'm not looking for full solutions here just a little direction.

```import math

print "What is the radius of your circle?(Enter as x.xx)"

radius = float(raw_input ("> "))
circumference = radius * 2.00 * math.pi

print "The circumference of your circle is: %d" % circumference
```

Is This A Good Question/Topic? 0

Replies To: I can't get a floating point number to calculate in a simple progr

#2 pidgeonpancakes

• New D.I.C Head

Reputation: 0
• Posts: 19
• Joined: 10-August 11

Re: I can't get a floating point number to calculate in a simple progr

Posted 22 March 2013 - 01:31 PM

I just figured out a solution. I changed the formatting from %d to %s and that solved the problem.
Was This Post Helpful? 0

#3 sepp2k

• D.I.C Lover

Reputation: 2311
• Posts: 3,574
• Joined: 21-June 11

Re: I can't get a floating point number to calculate in a simple progr

Posted 22 March 2013 - 01:50 PM

%f (for floating point) works too. The format specifier %d is used to print integers and, as you noticed, it will convert anything that isn't an integer to an integer before printing it.
Was This Post Helpful? 1

Page 1 of 1

 .related ul{list-style-type:circle;font-size:12px;font-weight:bold;}.related li{margin-bottom:5px;background-position:left 7px!important;margin-left:-35px;}.related h2{font-size:18px;font-weight:bold;}.related a{color:blue;}