RadNumericUpDown has the ability to format its value in three different formats specified by the ValueFormat property.
Here is a brief description of each value in the ValueFormat enumerator property.
- Numeric - used for numeric values without specific formatting, the default value is taken from the current culture of Windows. The specific Numeric format is described by all members of NumberFormatInfo starting with Numeric prefix.
- Currency - used for currency values, the default currency formatting is taken from the current culture of Windows. The specific Currency format is described by all members of NumberFormatInfo starting with Currency prefix.
- Percentage - used for percentage values, the default percentage value is taken from the current culture of Windows. The specific Percentage format is described by all members of NumberFormatInfo starting with Percentage prefix.
The following example shows how to use ValueFormat and NumberFormatInfo properties to achieve the deserved format:
CopyC#
private RadNumericUpDown TestMethod()
{
RadNumericUpDown numeric = new RadNumericUpDown();
numeric.Value = 15.50;
numeric.ValueFormat = ValueFormat.Numeric;
numeric.NumberFormatInfo = new NumberFormatInfo() { NumberDecimalDigits = 0 };
numeric.ValueFormat = ValueFormat.Currency;
numeric.NumberFormatInfo = new NumberFormatInfo() { CurrencyDecimalDigits = 2 };
numeric.ValueFormat = ValueFormat.Percentage;
numeric.NumberFormatInfo = new NumberFormatInfo() { PercentDecimalDigits = 1 };
return numeric;
}
CopyVB.NET
Private Function TestMethod() As RadNumericUpDown
Dim numeric As RadNumericUpDown = New RadNumericUpDown
numeric.Value = 15.50
numeric.ValueFormat = ValueFormat.Numeric
numeric.NumberFormatInfo = New NumberFormatInfo() With {
.NumberDecimalDigits = 0
}
//the display result is "16"
numeric.ValueFormat = ValueFormat.Currency
numeric.NumberFormatInfo = New NumberFormatInfo() With {
.CurrencyDecimalDigits = 2
}
//the display result is "$15.50"
numeric.ValueFormat = ValueFormat.Percentage
numeric.NumberFormatInfo = New NumberFormatInfo() With {
.PercentDecimalDigits = 1
}
//the display result is "%1500.5"
return numeric
End SubFor custom formatting RadNumericUpDown exposes additional property that is only used with the Numeric value of ValueFormat. CustomUnit is used to customize your formatting in case all the others type of formatting don't meet your needs.
Here is a simple example of how to use CustomUnit property:
CopyC#
private RadNumericUpDown TestMethod()
{
RadNumericUpDown numeric = new RadNumericUpDown();
numeric.Value = 10;
numeric.ValueFormat = ValueFormat.Numeric;
numeric.NumberFormatInfo = new NumberFormatInfo() { NumberDecimalDigits = 2 };
numeric.CustomUnit = "meters";
return numeric;
}
CopyVB.NET
Private Function TestMethod() As RadNumericUpDown
Dim numeric As RadNumericUpDown = New RadNumericUpDown
numeric.Value = 10
numeric.ValueFormat = ValueFormat.Numeric
numeric.NumberFormatInfo = New NumberFormatInfo() With {
.NumberDecimalDigits = 2
}
numeric.CustomUnit = "meters"
//the display result is "10.00 meters"
return numeric
End Sub