tinypig
V2EX  ›  问与答

如何禁止 Django 的 DecimalField 自动进位?

  •  
  •   tinypig · Sep 25, 2017 · 2928 views
    This topic created in 3303 days ago, the information mentioned may be changed or developed.

    如下的一个 Model

    class Test(models.Model)
        money = models.DecimalField('money', decimal_places=2, max_digits=8)
    
    t = TestApp.objects.create(money=100.005)
    t.money # 100.01 此处希望是 100.00
    

    是否可以配置自动 round down 而不是手动在 Save 之前 round down 呢?

    No Comments Yet
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   5598 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 01:36 · PVG 09:36 · LAX 18:36 · JFK 21:36
    ♥ Do have faith in what you're doing.