We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How can I hide the Zeros displayed when I set the property "CurrencyDecimalDigits" ?

Platform: WinForms |
Control: CurrencyTextBox |
Published Date: April 30, 2011 |
Last Revised Date: July 10, 2014

 

We can workaround the behaviour for now by handling the GotFocus and LostFocus events of CurrencyTextBox.Though we cannot hide the zeros ,you can set it in such a way that whenever the control does not have focus,it hides zeros.However, when it gets focus it shows the zeros according to the decimal digits.

C#

private void currencyTextBox1_GotFocus(object sender, System.EventArgs e)

{

this.currencyTextBox1.CurrencyDecimalDigits = 6;

}

 

private void currencyTextBox1_LostFocus(object sender, System.EventArgs e)

{

string dblval = this.currencyTextBox1.DecimalValue.ToString();

int decimalpos = this.currencyTextBox1.Text.IndexOf(".");

int len = dblval.TrimEnd(''0'').Substring(decimalpos).Length;

this.currencyTextBox1.CurrencyDecimalDigits = len;

}

VB

Private Sub currencyTextBox1_GotFocus(ByVal sender As Object, ByVal e As EventArgs) Handles currencyTextBox1.GotFocus

Me.currencyTextBox1.CurrencyDecimalDigits = 6

End Sub

 

Private Sub currencyTextBox1_LostFocus(ByVal sender As Object, ByVal e As EventArgs) Handles currencyTextBox1.LostFocus

Dim dblval As String = Me.currencyTextBox1.DecimalValue.ToString()

Dim decimalpos As Integer = Me.currencyTextBox1.Text.IndexOf(".")

Dim len As Integer = dblval.TrimEnd("0"c).Substring(decimalpos).Length

Me.currencyTextBox1.CurrencyDecimalDigits = len

End Sub

2X faster development

The ultimate WinForms UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon