nsValue: custom value which should be used to determine normalization shift
(val, prec, nsValue=None)
| 2 | |
| 3 | |
| 4 | def roundToPrec(val, prec, nsValue=None): |
| 5 | """ |
| 6 | nsValue: custom value which should be used to determine normalization shift |
| 7 | """ |
| 8 | # We're not rounding integers anyway |
| 9 | # Also make sure that we do not ask to calculate logarithm of zero |
| 10 | if int(val) == val: |
| 11 | return int(val) |
| 12 | roundFactor = int(prec - math.floor(math.log10(abs(val if nsValue is None else nsValue))) - 1) |
| 13 | # But we don't want to round integers |
| 14 | if roundFactor < 0: |
| 15 | roundFactor = 0 |
| 16 | # Do actual rounding |
| 17 | val = round(val, roundFactor) |
| 18 | # Make sure numbers with .0 part designating float don't get through |
| 19 | if int(val) == val: |
| 20 | val = int(val) |
| 21 | return val |
| 22 | |
| 23 | |
| 24 | def roundDec(val, prec): |
no outgoing calls
no test coverage detected