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 the number in str format contains a '.' character use split()
numsplit = str(num).split('.') num_int = int(numsplit[0]) num_dec = numsplit[1] # this is a string
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:
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.