how to get the length of a number
Felipe Almeida Lessa
felipe.lessa at gmail.com
Sun Jun 11 16:44:15 EDT 2006
Em Dom, 2006-06-11 às 20:10 +0000, Stan Cook escreveu:
> Can anyone tell me how to get the length of a number. I
> know len(string) will get the length of a string, but it
> doesn't like len(int). I seem to remember something like %s
> string. I tried to set a variable = to %s int, but that
> doesn't work. Is there a function I've forgotten about to
> convert an integer to a string?
To convert an integer i to a string:
str(i) or "%s" % i
To see how many decimal digits it has:
import math
math.ceil(math.log(i, 10))
--
Felipe.
More information about the Python-list
mailing list