forked from pyfa-org/Pyfa
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Round booster side-effect context menu
- Loading branch information
Showing
3 changed files
with
34 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import math | ||
|
||
|
||
def roundToPrec(val, prec, nsValue=None): | ||
""" | ||
nsValue: custom value which should be used to determine normalization shift | ||
""" | ||
# We're not rounding integers anyway | ||
# Also make sure that we do not ask to calculate logarithm of zero | ||
if int(val) == val: | ||
return int(val) | ||
roundFactor = int(prec - math.floor(math.log10(abs(val if nsValue is None else nsValue))) - 1) | ||
# But we don't want to round integers | ||
if roundFactor < 0: | ||
roundFactor = 0 | ||
# Do actual rounding | ||
val = round(val, roundFactor) | ||
# Make sure numbers with .0 part designating float don't get through | ||
if int(val) == val: | ||
val = int(val) | ||
return val | ||
|
||
|
||
def roundDec(val, prec): | ||
if int(val) == val: | ||
return int(val) | ||
return round(val, prec) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters