float

System.Single
Single Precision Floating Point (-3.402 E 38 to 3.4.02 E 38)
8 significant digits.
The default value is 0.

float myFloat; 
System.Single myFloat;

Explicit Data Type

You can append literal constants with the letter "F" or "f" when you need to specify this type of literal.

float myFloat = 1.6f                          ' suffix is necessary  
float myFloat = 1.6F ' suffix is necessary

Converting

// Float to Double 
float myFloat = 1.6F;
double myDouble = myFloat; ' implicit

// Float to Decimal
float myFloat = 1.6F;
decimal myDecimal = (int)myFloat; ' explicit

// Float to Integer
float myFloat = 1.6F;
int myInt = (int)myFloat; ' explicit

Examples

float myFloat = (float)4/3                    '= 1.33333  

Console.WriteLine( 4/3 ); '= 1
Console.WriteLine( (float)4/3 ); '= 1.33333

float.NaN 'NaN
float.IsNaN
float.PositiveInfinity '+∞
float.NegativeInfinity '-∞
-0.0f '-0

float myFloat = 1.0F / 0.0F 'Positive infinity
System.Diagnostics.Debug.Print myFloat '= Infinity

float myFloat = 0.0F / 0.0F 'Not a Number
System.Diagnostics.Debug.Print myFloat '= NaN

© 2024 Better Solutions Limited. All Rights Reserved. © 2024 Better Solutions Limited TopPrevNext