I wish to change an integer such as 23457689 to 689, 12457245 to 245 etc.
I do not require the numbers to be rounded and do not wish to have to convert to String.
Any ideas how this can be done in Python 2.7?
I wish to change an integer such as 23457689 to 689, 12457245 to 245 etc.
I do not require the numbers to be rounded and do not wish to have to convert to String.
Any ideas how this can be done in Python 2.7?
To handle both positive and negative integers correctly:
As a function where you can select the number of leading digits to keep:
The constraint to avoid converting to
str
is too pedantic. Converting tostr
would be a good way to do this if the format of the number might change or if the format of the trailing digits that need to be kept will change.Use the
%
operation:%
is themod
(i.e.modulo
) operation.