I want to remove digits from a float to have a fixed number of digits after the dot, like:
1.923328437452 -> 1.923
I need to output as a string to another function, not print.
Also I want to ignore the lost digits, not round them.
I want to remove digits from a float to have a fixed number of digits after the dot, like:
1.923328437452 -> 1.923
I need to output as a string to another function, not print.
Also I want to ignore the lost digits, not round them.
use numpy.round
The result of
round
is a float, so watch out (example is from Python 2.6):You will be better off when using a formatted string:
A general and simple function to use:
There is an easy workaround in python 3. Where to cut I defined with an help variable decPlace to make it easy to adapt.
Output:
Hope it helps.
Am also a python newbie and after making use of some bits and pieces here, I offer my two cents
str(int(time.time())) will take the time epoch as int and convert it to string and join with... str(datetime.now().microsecond)[:3] which returns the microseconds only, convert to string and truncate to first 3 chars
The truely pythonic way of doing it is