python - how to show a rounded decimal in a decimal form field in django -



python - how to show a rounded decimal in a decimal form field in django -

i have decimal form field. when instance showing want show value of 60.1 instead of 60.1111. model field 4 decimal places.

i know can alter date format this:

class accountpersonalinfoform(forms.modelform): class meta: model = client fields = ( 'amount', 'birth_date', ) def __init__(self, *args, **kwargs): super(accountpersonalinfoform, self).__init__(*args, **kwargs) self.fields['birth_date'].widget.format = '%b %d, %y' self.fields['birth_date'].input_formats = ['%b %d, %y'] #can round decimal format here? self.fields['amount'].widget.format = ???

how can round decimal show in decimal field 1 decimal place when model field 4 decimal places?

you can limiting floats digit after decimal point 1 using round or float("{0:.1f}".

check:

x= 60.1111 g = float("{0:.1f}".format(x)) h = round(x, 1) print h,g

python django django-models django-forms django-templates

Comments

Popular posts from this blog

assembly - What is the addressing mode for ld, add, and rjmp instructions? -

vowpalwabbit - Interpreting Vowpal Wabbit results: Why are some lines appended by "h"? -

Is there a way to convert an HTML page styled with Bootstrap CSS into email-compatible html? -