perpetualbeta perpetualbeta - 5 months ago 21 Question

Decimal.toString() for any region using VB.NET

I have an application that deals with currency. For display purposes I use the nifty VB FormatCurrency function which will format based on the OS's region setting. So, if in France you might get 123,45 whereas in the US you would get 123.45.

To perform the calculation on these amounts I use CDec() to convert to decimal.

My problem is that when I convert the Decimal to a String using toString() it formats according to the currently set region. I need to be able to always convert the decimal into a String representation for the US, i.e. with decimal points.

I thought I would be able to do something similar to this:


Try passing InvariantCulture into your ToString() method:

Dim dec As Decimal = 1.25D
//writes 1.25