Home »
VB.Net »
VB.Net Programs
VB.Net program to print given number in different formats using Format() function
By Nidhi Last Updated : November 16, 2024
Format() function in VB.Net
Here, we used the Format() function, which is used to get numbers in different formats based on style argument.
Syntax
Format(num, StyleArg)
Parameter(s)
- Date: Given number
- StyleArg: String Argument, which is used to specify the date format.
Return Value
The Format() function will return number in different formats in the form of string.
VB.Net code to print given number in different formats using Format() function
The source code to print a given number in different formats using the Format() function is given below. The given program is compiled and executed successfully.
'VB.Net program to print a number in different
'formats using Format() function.
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%
Press any key to continue . . .
Explanation:
In the above program, we created a module Module1 that contains a Main() method. In the Main() method, we created two variables result and num, here variable num initialized with "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)
In the above code, we used function Format(), here we passed numbers and different style arguments and then we printed the formatted number on the console screen.
VB.Net Basic Programs »