Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,890 questions

51,821 answers

573 users

How to display a float to 2 decimal places in VB.NET

4 Answers

0 votes
Imports System.IO

Module Module1

    Sub Main()

        Dim f As Double = 0.314F

        Try

            Console.WriteLine(f.ToString("0.00"))

        Catch ex As Exception

            Console.WriteLine(ex.Message)

        End Try

    End Sub

    'run:
    ' 
    '0.31

End Module

 



answered Jun 4, 2015 by avibootz
0 votes
Imports System.IO

Module Module1

    Sub Main()

        Dim f As Double = 0.3554F

        Try

            Console.WriteLine(f.ToString("0.00"))

        Catch ex As Exception

            Console.WriteLine(ex.Message)

        End Try

    End Sub

    'run:
    ' 
    '0.36

End Module

 



answered Jun 4, 2015 by avibootz
0 votes
Imports System.IO

Module Module1

    Sub Main()

        Dim f As Double = 0.314F

        Try

            Console.WriteLine(f.ToString("n2"))

        Catch ex As Exception

            Console.WriteLine(ex.Message)

        End Try

    End Sub

    'run:
    ' 
    '0.31

End Module

 



answered Jun 4, 2015 by avibootz
0 votes
Imports System.IO

Module Module1

    Sub Main()

        Dim f As Double = 0.314F

        Try

            Console.WriteLine(String.Format("{0:0.00}", f))

        Catch ex As Exception

            Console.WriteLine(ex.Message)

        End Try

    End Sub

    'run:
    ' 
    '0.31

End Module

 



answered Jun 4, 2015 by avibootz

Related questions

1 answer 124 views
1 answer 144 views
4 answers 364 views
2 answers 336 views
4 answers 504 views
2 answers 358 views
4 answers 142 views
...