using System; class Sample { public static void Main() { Console.WriteLine("(G) General:. . . . . . . . . {0:G} " + + -123, -123.45f); } }
Data Types
Format float point value as fixed point
using System; class Sample { public static void Main() { Console.WriteLine("(F) Fixed point:. . . . . . . {1:F} " + -123, -123.45f); } }
Format float number as scientific notation
Output float number as currency
using System; class Sample { public static void Main() { Console.WriteLine("(C) Currency: . . . . . . . . {0:C} " + -123, -123.45f); } }
Format float as decimal
using System; class Sample { public static void Main() { Console.WriteLine("(D) Decimal:. . . . . . . . . {0:D} " + -123, -123.45f); } }
Using Floats
/* * C# Programmers Pocket Consultant * Author: Gregory S. MacBeth * Email: gmacbeth@comporium.net * Create Date: June 27, 2003 * Last Modified Date: * Version: 1 */ using System; namespace Client.Chapter_1___Common_Type_System { public class UsingFloatsChapter_1___Common_Type_System { static void Main(string[] args) { float MyFloat = 3.281f; double MyDouble = 5E-02; } } }
Int and float value
/* Learning C# by Jesse Liberty Publisher: O'Reilly ISBN: 0596003765 */ using System; public class IntFloatTester { public static void Main() { int smallInt = 5; int largeInt = 12; int intQuotient; intQuotient = largeInt / smallInt; Console.WriteLine("Dividing integers. {0} / {1} = {2}", largeInt, smallInt, intQuotient); float smallFloat = 5; float largeFloat = 12; float FloatQuotient; FloatQuotient = largeFloat / smallFloat; Console.WriteLine("Dividing floats. {0} / {1} = {2}", largeFloat, smallFloat, FloatQuotient); } }