float

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

// double to float
double myDouble = 4.5;
float myFloat;
myFloat = (float)myDouble; // explicit

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

// decimal to float


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

// int to float
int myInt = 2;
float myFloat = myInt; ' implicit

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

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


Special Values

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

float myFloat = 1.0F / 0.0F 'Positive infinity
float myFloat = 0.0F / 0.0F 'Not a Number

System.Diagnostics.Debug.Print myFloat '= Infinity
System.Diagnostics.Debug.Print myFloat '= NaN

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