I am working on a project that has users entering Russian Currency in textboxes. I need to convert the entered text to decimal values to perform calculations with the entered values. I am having problems with getting this done. The code I developed follows:
Public Class RU Private Nfi As NumberFormatInfo = New CultureInfo("ru-RU", False).NumberFormat
private sub LoadRU Nfi.CurrencyDecimalSeparator = "," Nfi.CurrencyDecimalDigits = 2 Nfi.CurrencySymbol = "p" Nfi.CurrencyGroupSizes = New Integer() {3} Nfi.CurrencyGroupSeparator = " " End Sub
Private Sub uxPrincipalAmount_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles _ uxPrincipalAmount.LostFocus CalculateTotalDue End Sub
Private Sub CalculateTotalDue() uxTotalDue.Text = FormatCurrency(CDec(uxPrincipalAmount.Text)) + CDec(IIf(uxInterest.Text = "", 0, uxInterest.Text)) + _ CDec(IIf(uxAdditionalFees.Text = "", 0, uxAdditionalFees.Text)) End Sub
Error Received is: Приведение строки "3 500,00p" к типу 'Decimal' является недопустимым. translated to english "Reduction of a line " 3 500,00p " to type ' Decimal ' is inadmissible." The currency amount entered was "3 500,00p" This is the Russian format for entering currency as I know it to be correct.
I have also tried this: convert.ToDecimal("3 500,00p",Nfi) and received this message: "Input string was not in the correct format."
If I remove the "p", which is the currency symbol, from the statement as follows: convert.ToDecimal("3 500,00",Nfi) 3500D Which is what I would expect to be the return.
Am I not seeing something here with the NumberFormat? Should the convert work with the currency symbol in the string? I can remove the currency symbol if that is the "fix" for this. Thanks in advance.
THANK YOU Reed! I've been struggling with this and your answer is the only one that worked!
Microsoft sta conducendo un sondaggio in linea per comprendere l'opinione degli utenti in merito al sito Web di Msdn. Se si sceglie di partecipare, quando si lascia il sito Web di Msdn verrà visualizzato il sondaggio in linea.