The title doesn't really make sense, as a number with some thing like .23238382 attached to the back of it isn't an integer, but that's not the point. I want to make a program that places commas in the correct position in a number you give. Well, in some of the division equations I need to do, some of the numbers have a decimal on the back and a bunch of numbers, which throws off the program, so I can't seem to figure out a way to take the decimal and numbers behind it off of the number. Any help would be greatly appreciated :)
AutoPython 5 Junior Poster
Recommended Answers
Jump to PostIf all you want to do is remove the floating point digits you could do this:
floatValue=3.141 integerValue = int(floatValue) print "The integer equivalent of", floatValue, "is", integerValue
Note: The above code is python 2.x syntax. For python 3.x change the print statement to:
Jump to PostTo round off decimal
IDLE 2.6.2 >>> 0.0225 0.022499999999999999 >>> round(0.0225, 3) 0.023 >>> round(0.0225, 2) 0.02 >>> a = 15.1548 >>> print '%.2f' % a 15.15 >>> print '%.3f' % a 15.155 #Look at type >>> s = '1.458045577554545454' >>> type(s) <type 'str'> >>> x = …
All 5 Replies
djidjadji 28 Light Poster
JasonHippy 739 Practically a Master Poster
JasonHippy 739 Practically a Master Poster
snippsat 661 Master Poster
AutoPython 5 Junior Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.