ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT

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

Here, we are going to learn how to print given number in different formats using Format() function in VB.Net?
Submitted by Nidhi, on December 06, 2020

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

Syntax:

Format(num, StyleArg)

Parameters:

  • 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.

Program/Source Code:

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 »



ADVERTISEMENT



ADVERTISEMENT



Comments and Discussions

ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.