Using numpy or python's standard library, either or. How can I take a value with several decimal places and truncate it to 4 decimal places? I only want to compare floating point numbers to their first 4 decimal points.
+1
A:
you can use decimal module, especially the part on getcontext().prec
ghostdog74
2010-02-24 02:50:16
+3
A:
If you want to compare two floats, you can compare on abs(a-b) < epsilon
where epsilon is your precision requirement.
Goran Rakic
2010-02-24 02:54:48
+6
A:
round(a_float, 4)
>>> help(round)
Help on built-in function round in module __builtin__:
round(...)
round(number[, ndigits]) -> floating point number
Round a number to a given precision in decimal digits (default 0 digits).
This always returns a floating point number. Precision may be negative.
>>>
John Machin
2010-02-24 02:54:58