Created
December 27, 2018 06:59
-
-
Save MaHu6/517b43d8081cdc3d24dd9b5653e51c89 to your computer and use it in GitHub Desktop.
Keep a few decimal places in python
This file contains hidden or 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
| def keep_decimal(origin_num, places): | |
| num_x, num_y = str(origin_num).split('.') | |
| if len(num_y) > places: | |
| num = float(num_x + '.' + num_y[0:places]) | |
| else: | |
| return origin_num | |
| return num |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment