V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
tinypig
V2EX  ›  问与答

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

  •  
  •   tinypig · Sep 25, 2017 · 2568 views
    This topic created in 3138 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   ·   Solana   ·   5280 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 46ms · UTC 03:24 · PVG 11:24 · LAX 20:24 · JFK 23:24
    ♥ Do have faith in what you're doing.