Home >>VB.Net Built-in Functions >VB.Net program to print given number in different formats using Format() function

VB.Net program to print given number in different formats using Format() function

Write a VB.Net program to print given number in different formats using Format() function

Here, we used the function Format(), which is used to get numbers based on style arguments in multiple formats.

Syntax :

Format(num, StyleArg)

Parameters :

  • Date: Given number, given number
  • StyleArg: String Argument used to determine the format of the date.

Return Value :

The Format() function returns the number as a string in different formats.

Program :

The source code to print a given number using the Format() function in various formats is given below. The program given is compiled and successfully executed.


Module Module1
    Sub Main()
        Dim result As String
        Dim num As Integer = 12345678
        result = Format(num, "General Number")
        Console.WriteLine(result)
        result = Format(num, "Fixed")
        Console.WriteLine(result)
        result = Format(num, "Standard")
        Console.WriteLine(result)
        result = Format(num, "Currency")
        Console.WriteLine(result)
        result = Format(num, "Percent")
        Console.WriteLine(result)
    End Sub
End Module
	
Output:
12345678
12345678.00
12,345,678.00
$12,345,678.00
1234567800.00%

Explanation:

We created a Module1 module in the program above that contains the Main() method. Two variables result and num, here variable num initialized with "12345678" were developed in the Main() method.

result = Format(num, "General Number")
Console.WriteLine(result)

result = Format(num, "Fixed")
Console.WriteLine(result)

result = Format(num, "Standard")
Console.WriteLine(result)

result = Format(num, "Currency")
Console.WriteLine(result)

result = Format(num, "Percent")
Console.WriteLine(result)

We used the Format() function in the above code, passed numbers and style arguments here, and then printed the formatted number on the console screen.


No Sidebar ads