Currency Problem with DecimalSeperator

# Thread: Currency Problem with DecimalSeperator

1. Senior Member
Join Date
Dec 1969
Posts
225

## Currency Problem with DecimalSeperator

Hi,<BR><BR>I am an English programmer, working out of Spain at the moment.<BR><BR>I have written an ASP.net shopping system for a Spainish company.<BR><BR>Everything works great EXCEPT, when I sent the shopping cart to PayPal.<BR><BR>The spanish format numbers differently to us in the UK and US.<BR><BR>One thousand, five hundred and 10 point 25 would be formatted:<BR><BR>1.510,25<BR><BR>NOT<BR><BR>1,510 .25 as we would do it.<BR><BR>Therefore, when I send the total to PayPal, it complains that I have sent an invalid amount.<BR><BR>To solve this, I had briefly thought about just replacing the .&#039;s with ,&#039;s. But this is a really nasty way of doing it. Especially as the company has UK and US offices and will presumably want to use this code there.<BR><BR>Can anybody help me out with a PROPER way of doing this. I have looked at the Globalization base-classes, but cannot see figure it out.<BR><BR>Many thanks,<BR><BR>James Andrews.

2. Senior Member
Join Date
Dec 1969
Posts
2,885

## RE: Currency Problem with DecimalSeperator

I was just playing around with this - it may be a starting point for you.<BR><BR>[code language="C#"]<BR>private void runTest()<BR>{<BR> System.Globalization.CultureInfo ciES = new System.Globalization.CultureInfo("es-BO");<BR> System.Globalization.CultureInfo ciEN = new System.Globalization.CultureInfo("en-US");<BR> <BR> string total = "1510.25";<BR><BR> Response.Write("Spanish: " + Convert.ToDecimal(total).ToString(ciES) + "<BR>");<BR> // Above returns 1510,25<BR><BR> Response.Write("English: " + Convert.ToDecimal(total).ToString(ciEN));<BR> // Above 1510.25<BR>}<BR><BR>[/code]

3. Senior Member
Join Date
Dec 1969
Posts
225

## RE: Currency Problem with DecimalSeperator

Thanks very much Chris for putting me on the right track!<BR><BR>For anyone else who reads this in the future, I made this VB.net class to solve the problem:<BR><BR>Public Class NumberFixer<BR> Public Function FixEuropeanNumberFormat(ByVal Amount As String, ByVal ToEuropean As Boolean, ByVal ReturnCurrency As Boolean) As String<BR> Dim nfiUS As NumberFormatInfo = New CultureInfo("en-US", False).NumberFormat<BR> Dim nfiES As NumberFormatInfo = New CultureInfo("es-ES", False).NumberFormat<BR><BR> Dim sfmtType As String = "N"<BR><BR> If ReturnCurrency Then<BR> sfmtType = "C"<BR> End If<BR><BR> If ToEuropean Then<BR> Dim myInt As Decimal = Convert.ToDecimal(Amount, nfiUS)<BR> Return myInt.ToString(sfmtType, nfiES)<BR> Else<BR> Dim myInt As Decimal = Convert.ToDecimal(Amount, nfiES)<BR> Return myInt.ToString(sfmtType, nfiUS)<BR> End If<BR> End Function<BR> End Class<BR><BR>Hopefully other people will find this useful.<BR><BR>Happy Coding ;D<BR><BR>James.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•