1👍
You can work with the round(…)
builtin function [python-doc]:
>>> round(Decimal('0.123456789'), 2)
Decimal('0.12')
>>> round(Decimal('0.123456789'), 3)
Decimal('0.123')
You can thus construct a new Decimal
by rounding a Decimal
with a given number of decimals.
0👍
For conversions, access the preferred unit attribute to get a converted distance quantity:
d1 = Distance(km=5)
print(d1.mi) # Converting 5 kilometers to miles
3.10685596119
print(d2.km) # Converting 5 miles to kilometers
8.04672
source Django Docs
- [Answered ]-Reading an excel file, extracting each cell value as a str and doing some action on each cell value, Python
- [Answered ]-DRF-How to update single field in create method of model serializer
- [Answered ]-In Django, how can I create a independent combobox that doesn't use the database?
- [Answered ]-Django Boto and Upload to S3 is a 400 Bad Request
- [Answered ]-Accessing a List out of order in Jinja
Source:stackexchange.com