title: Xamarin forms limit number of decimal places in an entry field
body: <p>I have an entry field inside of a collection view cell. The entry field should accept numeric value only with certain decimal places. I don't want more input if they exceed the decimal places. The decimal places vary for each cell. How do I create this validation in Model or using behaviour/trigger?</p>
  <p>Currently, my code is like this</p>
  <pre><code>&lt;Entry Placeholder=&quot;Quantity&quot;
         Keyboard=&quot;Numeric&quot;
         Text=&quot;{Binding EnteredQuantity, Mode=TwoWay}&quot;/&gt;
  </code></pre>
  <p>And in the model part, I am doing this</p>
  <pre><code>private string enteredQuantity = &quot;1&quot;;
  
          public string EnteredQuantity
          {
              get =&gt; enteredQuantity;
  
              set
              {
                  if (!decimal.TryParse(value, out decimal parsedQuantity))
                  {
                      enteredQuantity = &quot;1&quot;;
                      OnPropertyChanged(enteredQuantity);
                  }
                  else
                  {
                      if (parsedQuantity &gt; 9999.99M)
                      {
                          enteredQuantity =string.Format(&quot;9999.99&quot;, parsedQuantity);
                          OnPropertyChanged(enteredQuantity);
                      }
                      else
                      {
                          string formatString = &quot;{&quot; + &quot;0:0.&quot;.PadRight(4 + (int) BaseDecimalPlaces, '#') + &quot;}&quot;; //Format of {0:0.##}
                          if (IsAlternateUnitUsed &amp;&amp; selectedUnit.Value == &quot;A&quot;)
                          {
                              formatString = &quot;{&quot; + &quot;0:0.&quot;.PadRight(4 + (int) AlternateDecimalPlaces, '#') + &quot;}&quot;;
                          }
  
                          enteredQuantity = string.Format(formatString, parsedQuantity);
                          OnPropertyChanged(enteredQuantity);
                      }
                  }
              }
          }
  </code></pre>
  <p>For the above test, the format string is {0:0.##} and decimal places are 2.
  I am trying to restrict the value in the Binding property. However, this does not reflect on the front end. The frontend will show any decimal places like in the picture below. Does anybody have an idea how to solve this?</p>
  <p><a href="https://i.stack.imgur.com/ajsM2.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ajsM2.png" alt="Sample screenshot" /></a></p>
  <p>Has</p>