Csharp/C Sharp/Data Types/float
Format a float number in ToString method
<source lang="csharp">
using System; public class MainClass {
public static void Main() { Console.WriteLine(10.3.ToString("C", null)); // $10.30 }
}
</source>
Int and float value
<source lang="csharp"> /* 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); } } </source>
Using Floats
<source lang="csharp"> /*
* 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; } }
}
</source>