VB.Net/Development/NumberFormat

Материал из VB Эксперт
Перейти к: навигация, поиск

Localization NumberFormat

  
Imports System.Globalization
Imports System.Threading

Module Module1
   Sub Main()
      Dim FRCulture As New CultureInfo("fr-FR")
      Dim MyCulture As New CultureInfo(Thread.CurrentThread.CurrentUICulture.LCID)
      Dim Vnf As NumberFormatInfo
      Console.WriteLine(123456.ToString("c", MyCulture))
      Vnf = MyCulture.NumberFormat
      Vnf.CurrencyDecimalSeparator = ","
      Vnf.CurrencyGroupSeparator = "."
      Vnf.NumberDecimalSeparator = ","
      Vnf.NumberGroupSeparator = "."
      MyCulture.NumberFormat = Vnf
      Console.WriteLine(123456.ToString("C", MyCulture))
      MyCulture.NumberFormat = FRCulture.NumberFormat
      Console.WriteLine(123456.ToString("c", MyCulture))
   End Sub
End Module


Ordinal Numbers

  
Public Class MainClass
    Public Shared Function GetOrdinal(ByVal Number As Integer) As String
        If CType(Number, String).Length > 2 Then
            Dim intEndNum As Integer = CType(CType(Number, String).Substring(CType(Number, String).Length - 2, 2), Integer)
            If intEndNum >= 11 And intEndNum <= 13 Then
                Select Case intEndNum
                    Case 11, 12, 13
                        Return "th"
                End Select
            End If
        End If
        If Number >= 21 Then
            Select Case CType(Number.ToString.Substring(Number.ToString.Length - 1, 1), Integer)
                Case 1
                    Return "st"
                Case 2
                    Return "nd"
                Case 3
                    Return "rd"
                Case 0, 4 To 9
                    Return "th"
            End Select
        Else
            Select Case Number
                Case 1
                    Return "st"
                Case 2
                    Return "nd"
                Case 3
                    Return "rd"
                Case 4 To 20
                    Return "th"
            End Select
        End If
    End Function
    Public Shared  Sub Main
        System.Console.WriteLine(GetOrdinal("123"))
    End Sub
End Class