Framework 4.0 Asp.net application
When I run the code I got a error \"The value \'999.9999\' of the MaximumValue property of \'RangeValidator\' cannot be c
The RangeValidator uses the NumberFormatInfo.CurrencyDecimalDigits property to determine if the string can be converted to a currency, otherwise it will throw your exception. From MSDN:
when a RangeValidator control's Type property is set to "Currency", the MinimumValue and MaximumValue properties must be provided in a format such as that described in NumberFormatInfo.CurrencyDecimalDigits, otherwise an exception is thrown.
The default for most cultures (incl. InvariantCulture
) is 2 (arabic countries have 3 but none 4).
So what culture are you using? If it is important to store more decimal places than two in a currency, then you could use a custom NumberFormatInfo
in this page:
protected void Page_PreInit(object sender, EventArgs e)
{
var customCulture = (CultureInfo)CultureInfo.CurrentCulture.Clone();
var nfi = (NumberFormatInfo)customCulture.NumberFormat.Clone();
nfi.CurrencyDecimalDigits = 4;
customCulture.NumberFormat = nfi;
System.Threading.Thread.CurrentThread.CurrentCulture = customCulture;
}
(note that you need to add using System.Globalization;
at the top)