Format a textbox to display as a percentage

  • Thread starter Thread starter John
  • Start date Start date
J

John

Arrggg…Format String Hell…Hello there,

I am attempting to format a decimal value as a % (percentage).
That is; I want .12 to be displayed and edited as 12%
No matter what I try I cant get it to work :(
I can get it working for display format, but not for the editformat :(

Below is my code

Me.txtDefaultAdminFeePercentage.Properties.DisplayFormat.FormatType =
FormatType.Numeric
Me.txtDefaultAdminFeePercentage.Properties.DisplayFormat.FormatString =
"{0:0%}"
Me.txtDefaultAdminFeePercentage.Properties.EditFormat.FormatType =
FormatType.Numeric
Me.txtDefaultAdminFeePercentage.Properties.EditFormat.FormatString =
"{0:0%}"

Any ideas would be greatly appreciated

Thank you for taking the time to read my post
John
 
Arrggg...Format String Hell...Hello there,

I am attempting to format a decimal value as a % (percentage).
That is; I want .12 to be displayed and edited as 12%
No matter what I try I cant get it to work :(
I can get it working for display format, but not for the editformat :(

Below is my code

Me.txtDefaultAdminFeePercentage.Properties.DisplayFormat.FormatType =
FormatType.Numeric
Me.txtDefaultAdminFeePercentage.Properties.DisplayFormat.FormatString =
"{0:0%}"
Me.txtDefaultAdminFeePercentage.Properties.EditFormat.FormatType =
FormatType.Numeric
Me.txtDefaultAdminFeePercentage.Properties.EditFormat.FormatString =
"{0:0%}"

Any ideas would be greatly appreciated

Thank you for taking the time to read my post
John

Instead of using a textbox you might try using the masked text box
control instead (it should be listed in the components somewhere).
Then set the mask property. I'm sure this kind of thing is ideal for
it's use.

Phill
 
Arrggg…Format String Hell…Hello there,

I am attempting to format a decimal value as a % (percentage).
That is; I want .12 to be displayed and edited as 12%
No matter what I try I cant get it to work :(
I can get it working for display format, but not for the editformat :(

Below is my code

Me.txtDefaultAdminFeePercentage.Properties.DisplayFormat.FormatType =
FormatType.Numeric
Me.txtDefaultAdminFeePercentage.Properties.DisplayFormat.FormatString =
"{0:0%}"
Me.txtDefaultAdminFeePercentage.Properties.EditFormat.FormatType =
FormatType.Numeric
Me.txtDefaultAdminFeePercentage.Properties.EditFormat.FormatString =
"{0:0%}"

Any ideas would be greatly appreciated

Thank you for taking the time to read my post
John

The format string you want is {0:p}

That will give you 12.00%
 
Back
Top