google-site-verification=ECX1M6_Vb39ty4VtQDXQce6wOjmPTxSettd3hTIZb9Q

Format String to 2 Decimal Places VB.Net

random

Format String to 2 Decimal Places VB.Net

This blog post demonstrates how to format float numbers to string format in VB.net. You can use static method String.Format or instance methods double.ToString and float.ToString. Find the vb.net code snippet below :-
Standard Numeric Format Strings, vb.net - String 3 decimal places,string format 2 decimal places,Formatting number with two decimal places,fomat string with 2 decimal places,How to format string to decimal,VB.NET String.Format Examples,Rounding Number to 2 Decimal Places
string format double
Console App
Module Module1
    Sub Main()
        Dim list As ArrayList = New ArrayList()
        list.Add("5")
        list.Add("60")
        list.Add("25.5")
        list.Add("85.56")

        ' Get array of objects.
        Dim array() As Object = list.ToArray()

        For Each element In array

            'Cast object to Decimal
            Dim value As Decimal = element

            ' 1st way
            Console.WriteLine(Format(value, "0.00"))
            Console.WriteLine()

            ' 2nd way
            Console.WriteLine(CStr(value.ToString("#,##0.00")))
            Console.WriteLine()

            ' 3rd way
            Console.WriteLine((value.ToString("N2")))
            Console.WriteLine()

            ' 4th way
            Console.WriteLine(String.Format("{0:f2}", CType(value, Decimal)))
        Next
        Console.ReadKey()
    End Sub
End Module 
Format String to 2 Decimal Places VB.Net Reviewed by Ravi Kumar on 10:16 PM Rating: 5

No comments:

All Rights Reserved by Etechpulse © 2012 - 2017

Contact Form

Name

Email *

Message *

Powered by Blogger.