「VB.NET」Formatメソッドで指定値を指定書式で設定する

2021年11月29日

書式
Format(任意の値, 設定する書式)
文字列の 1 つ以上の書式項目を、指定されたオブジェクトの文字列表記に置換します。
Public Shared Function Format (format As String, arg0 As Object) As String
パラメーター
format 複合書式設定文字列
arg0 書式指定するオブジェクト
使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
Module Module1
Public Sub Main()
Dim strMsg As String
strMsg = Format(4567.8, "##,##0.00")
Console.WriteLine(strMsg)
strMsg = Format(1234.6, "###0.00")
Console.WriteLine(strMsg)
strMsg = Format(4, "0.00%")
Console.WriteLine(strMsg)
Console.ReadKey()
End Sub
End Module
Module Module1 Public Sub Main() Dim strMsg As String strMsg = Format(4567.8, "##,##0.00") Console.WriteLine(strMsg) strMsg = Format(1234.6, "###0.00") Console.WriteLine(strMsg) strMsg = Format(4, "0.00%") Console.WriteLine(strMsg) Console.ReadKey() End Sub End Module
Module Module1

    Public Sub Main()

        Dim strMsg As String

        strMsg = Format(4567.8, "##,##0.00")
        Console.WriteLine(strMsg)

        strMsg = Format(1234.6, "###0.00")
        Console.WriteLine(strMsg)

        strMsg = Format(4, "0.00%")
        Console.WriteLine(strMsg)

        Console.ReadKey()
    End Sub

End Module

実行結果

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
4,567.80
1234.60
400.00%
4,567.80 1234.60 400.00%
4,567.80
1234.60
400.00%

 

VB.net

Posted by arkgame