Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

decimal character

Status
Not open for further replies.

stx

Programmer
Sep 24, 2002
62
BE
hi

is it possible to change the decimal character for my app only to "." instead of a "," or vice versa.
 
The decimal character in numbers comes from the current CultureInfo class, which has a NumberFormat property, which is of type NumberFormatInfo. Class NumberFormatInfo has a property named NumberDecimalSeparator, which is the decimal character for that culture.

So... if you want to change how your numbers are formatted, you should use another CultureInfo object. You can do this by:
Code:
Imports System
Imports System.Globalization

Public Class TestClass

   Public Shared Sub Main()
      Dim i As Integer = 100
      
      ' Create a CultureInfo object for English in Belize.
      Dim bz As New CultureInfo("en-BZ")
      ' Display i formatted as currency for the bz.
      Console.WriteLine(i.ToString("c", bz))
      
      ' Create a CultureInfo object for English in the U.S.
      Dim us As New CultureInfo("en-US")
      ' Display i formatted as currency for us.
      Console.WriteLine(i.ToString("c", us))
      
      ' Create a CultureInfo object for Danish in Denmark.
      Dim dk As New CultureInfo("da-DK")
      ' Display i formatted as currency for dk.
      Console.WriteLine(i.ToString("c", dk))
   End Sub
End Class
You get:
BZ$100.00
$100.00
kr100,00

As a side benefit, your dates will also be formatted correctly for the new culture.

Chip H.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top