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,819 answers

573 users

How to display a float to 2 decimal places in C#

4 Answers

0 votes
using System;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            float f = 0.314f;

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

/*
run:

0.31
 
*/

 



answered Jun 4, 2015 by avibootz
edited Feb 18, 2016 by avibootz
0 votes
using System;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            float f = 0.3554f;

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

/*
run:

0.36
 
*/

 



answered Jun 4, 2015 by avibootz
edited Feb 18, 2016 by avibootz
0 votes
using System;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            float f = 0.314f;

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

/*
run:

0.31
 
*/

 



answered Jun 4, 2015 by avibootz
edited Feb 18, 2016 by avibootz
0 votes
using System;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            float f = 0.314f;

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

/*
run:

0.31
 
*/

 



answered Jun 4, 2015 by avibootz
edited Feb 18, 2016 by avibootz

Related questions

4 answers 395 views
2 answers 336 views
4 answers 504 views
2 answers 358 views
1 answer 104 views
2 answers 213 views
1 answer 180 views
...