-1

I have this function and I want to allow only 2 decimal places for the value.

This is not a model field but it's being calculated from them. What is the right way to do it?

@property
def value(self):
    value = self.average_flow_rate * (self.d_n / 1000) / self.nu
    if 2320 < value < 4000:
        return 4000
    else:
        return value
Kye
  • 4,279
  • 3
  • 21
  • 49
Xhens
  • 804
  • 3
  • 13
  • 33

1 Answers1

2

This should work like a charm:

round(self.d_n, 2)
Silwest
  • 1,620
  • 1
  • 15
  • 29
  • Thanks. I solved it. The problem was at template rendering where I had put: `{{ form.instance.value|stringformat:"d" }}` instead of ".2f" – Xhens Jul 20 '17 at 11:13