Home >>VB.Net Built-in Functions >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 :
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
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.