Posted by : Anwar Hossain
Category : asp.net c # basic tutorial

String Format Example using ASP.Net C#

Dear viewers in this tutorial I will show how to format double type data using String.Format Method using C # .First example I have shown to format only two decimal number second example shown to format only two decimal number from floating number ,third example shown to format minimum number of digits before decimal point ,forth example shown to use thousands separator use zero and comma separator before an usual float formatting pattern.

Common String Format Method example C #

 

Common String Format Method example C sharp

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

 

namespace ExamleStringFormat

{

 

    class Program

    {

        static void Main(string[] args)

        {

 

        

            Console.WriteLine("\n Only two decimal Number");

            Console.WriteLine("\n For two decimal we need to use pattern (0.00)");    

            Console.WriteLine("\n {0}", String.Format("{0:0.00}", 189.6667));

            Console.WriteLine("\n {0}", String.Format("{0:0.00}", 183.894));

            Console.WriteLine("\n {0}", String.Format("{0:0.00}", 196.0));

         

            Console.WriteLine("\n Floating number of decimal Number");

            Console.WriteLine("\n For Floating decimal we need to use pattern (0.##)");

            Console.WriteLine("\n {0}", String.Format("{0:0.##}", 189.666745665845));

            Console.WriteLine("\n {0}", String.Format("{0:0.##}", 183.8942654566));

            Console.WriteLine("\n {0}", String.Format("{0:0.##}", 196.0));

 

            Console.WriteLine("\n At least two digits before decimal point ");

            Console.WriteLine("\n For  decimal we need to use pattern (00.0)");

            Console.WriteLine("\n {0}", String.Format("{0:00.0}", 189.4567));

            Console.WriteLine("\n {0}", String.Format("{0:00.0}", 89.4567));

            Console.WriteLine("\n {0}", String.Format("{0:00.0}", 9.4567));

            Console.WriteLine("\n {0}", String.Format("{0:00.0}",-9.4567));

 

            Console.WriteLine("\n Thousands separator");

            Console.WriteLine("\n For Thousands separator we need to use pattern (0,0.0)");

            Console.WriteLine("\n {0}", String.Format("{0:0,0.0}", 18129.4567));

            Console.WriteLine("\n {0}", String.Format("{0:0,0}", 12589.4567));

          

            Console.ReadLine();

 

           

        }

    }

   

  

}

 

Out Put

C_Sharp_String_Class_Methods



Realted Article Headline

How to find odd number in c #
How to generate random number in c #
Nested For Loop Example in C Sharp
Store C sharp reference type in a List C#
Find number of items in a List C#
Concept about C # List
Custom Time formatting example C #
Custom Date formatting example C #
String Format Example using ASP.Net C#
Simple enum example in C Sharp
Nested switch-case statement example in C #
Combined switch...case statement example in C #
C Sharp switch case statement Example
C# SUM ArrayList Element Example
C# String Class Methods Example
C Sharp String Class Properties and Methods
C Sharp String Class Example
How to join two ArrayList collections in C#.
How to Use C Sharp Math Class
C Sharp ArrayList Property and Method
C Sharp ArrayList Example
C Sharp Arrays Example
C Sharp Logical operator Example
C Sharp Relational operators
C Sharp Arithmetic operators Example
C Sharp Common Assignment Operator
Simple for loop example in c sharp

Article Category

How to create asp.net control dynamically
Learn HTML for beginner
DataList example in C Sharp
Mail sending in asp.net c#
State Management in ASP C #
Basic sql tutorial for Beginner
DataTable example in ASP.Net C#
How to use LINQ in ASP.NET C#
asp.net c # basic tutorial
How to use ajax toolkit in asp.net C#
How to use different types of validation control using asp.net c#
How to use grid view in asp.net c#
Protected by Copyscape Online Plagiarism Detection