Prechádzať zdrojové kódy

[Form] fixed decimal rounding in IntegerField

Instead of rounding half-up (round to nearest neighbor) act as an integer cast
would and always round down (round towards zero).
Brandon Turner 14 rokov pred
rodič
commit
9e84f450c2

+ 5 - 0
src/Symfony/Component/Form/IntegerField.php

@@ -2,6 +2,8 @@
 
 namespace Symfony\Component\Form;
 
+use Symfony\Component\Form\ValueTransformer\NumberToLocalizedStringTransformer;
+
 /*
  * This file is part of the symfony package.
  * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
@@ -24,6 +26,9 @@ class IntegerField extends NumberField
     {
         $this->addOption('precision', 0);
 
+        // Integer cast rounds towards 0, so do the same when displaying fractions
+        $this->addOption('rounding-mode', NumberToLocalizedStringTransformer::ROUND_DOWN);
+
         parent::configure();
     }