Category / Section
How to set the MaximumDecimalDigits in NumericTextBox
1 min read
The Maximum number of digits to be displayed after the decimal part of NumericTextBox can be specified by using MaximumNumberDecimalDigits property. It takes only the positive value.
The following steps will need to set the MaximumNumberDecimalDigits in NumericTextBox
Step 1: Add necessary assemblies
Step 2: Set the MaximumNumberDecimalDigits property value with positive value.
The following code example will helpful to view the NumericTextBox with MaximumNumberDecimalDigits as 3
Code Snippet
C# Code
namespace KBSolution { public partial class KBSolutionPage : ContentPage { public KBSolutionPage() { InitializeComponent(); Grid grid = new Grid() { BackgroundColor = Color.FromHex("E4EAF0") }; grid.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(30) }); grid.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(50) }); Label firstNumeric = new Label() { Text = "NumericTextBox", FontSize = 20, HorizontalOptions = LayoutOptions.Center, FontAttributes = FontAttributes.Bold, HorizontalTextAlignment = TextAlignment.Start, VerticalTextAlignment = TextAlignment.Start }; SfNumericTextBox sfNumericTextBox = new SfNumericTextBox() { WidthRequest = 180, ParserMode = Parsers.Decimal, HorizontalOptions = LayoutOptions.Center, MaximumNumberDecimalDigits = 3, AllowNull = true, BorderColor = Color.Blue, TextColor = Color.Maroon, Value = 1000, FormatString = "n", ValueChangeMode = ValueChangeMode.OnKeyFocus, PercentDisplayMode = PercentDisplayMode.Value, FontSize = 20 }; grid.Children.Add(firstNumeric, 0, 0); grid.Children.Add(sfNumericTextBox, 0, 1); this.Content = grid; } } }
XAML Code
<?xml version="1.0" encoding="utf-8"?> <ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:local="clr-namespace:KBSolution" xmlns:Synfusion="clr-namespace:Syncfusion.SfNumericTextBox.XForms;assembly=Syncfusion.SfNumericTextBox.XForms" x:Class="KBSolution.KBSolutionPage"> <ContentPage.Content> <Grid BackgroundColor="#E4EAF0"> <Grid.RowDefinitions> <RowDefinition Height="30"/> <RowDefinition Height="50"/> </Grid.RowDefinitions> <Label x:Name="firstNumeric" Text="NumericTextBox" FontSize="20" HorizontalOptions="Center" FontAttributes="Bold" HorizontalTextAlignment="Start" VerticalTextAlignment="Start"/> <Synfusion:SfNumericTextBox Grid.Row="1" WidthRequest="180" ParserMode="Decimal" HorizontalOptions="Center" HeightRequest="40" MaximumNumberDecimalDigits="3" AllowNull="true" BorderColor="Blue" TextColor="Maroon" x:Name="sfNumericTextBox" Value="1000" FormatString="n" ValueChangeMode="OnKeyFocus" PercentDisplayMode="Value" FontSize="20" /> </Grid > </ContentPage.Content> </ContentPage>