[Django]-Django modelfield, how do I get the actual value?

1👍

You can get Decimal object value by casting it to float.

Example:

dec = Number.objects.get(id=1).decimal
dec = float(dec)

Or even

dec = str(dec) #Please note this converts to  a string type. 

One more way would be

dec = format(dec, '.2f') #Or change the precision to cater to your needs

Please note, it is not a good idea to use decimal as a variable name

Leave a comment