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 converted to type ‘Currency’.
Below is my code:
<asp:RangeValidator Runat='server' ControlToValidate='textEdit'
MinimumValue='0.0001'
MaximumValue='999.9999' Type='Currency'
ErrorMessage='Should be between 0.0001 and 999.9999' id="idValidtor"
display='None' />
Please explain me is currency value can’t contain more than 2 digits after decimal?
Unless how can I resolve this issue?
The
RangeValidatoruses theNumberFormatInfo.CurrencyDecimalDigitsproperty to determine if the string can be converted to a currency, otherwise it will throw your exception. From MSDN: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
NumberFormatInfoin this page:(note that you need to add
using System.Globalization;at the top)