A floating point

Soldato
Joined
27 Mar 2004
Posts
14,081
Location
Between Realities
So I can be rather dense.

I'm trying to learn what a floating point number is, with regards to C# programming and I cant find an explanation I understand. Can anyone dumb it down for me?

I have googled, And the answers I'm getting are along these lines:-

float : A fractional (floating point) number (eg, 3.25907).
Can be a number between roughly 1.5 x 10^45 to 3.4 10^38, in floating point format.

Okay cool, but why would use use a float?

I get INT, Boolean and Strings. But floats, I'm not getting the reasoning behind them?

Float = 1.5 x 10^45 to 3.4 10^3 just baffles me.

Is it just a number with a decimal point? :o
 
A float is just a number that isn't an integer. Lets look at the result of 10/4. The answer is 2.5. You would have to use a float to represent that number as it isn't an integer.

The 1.5*10^45 bit just tells you the biggest number that can be supported in that compilers range. This will depend on the compliler, the CPU etc. This kind of exponential notation is used to write down very big and very small numbers. For example 1.25*10^35 is a lot easier to write down than 125000000000000000000000000000000000. Look up exponential notation if you want to understand more about this.
 
A floating point variable is simply a number where the decimal place can float around. So it could hold a value of, for example, 12345.7 or it could hold a value like 65432.8999867.

In ye olden days of mainframe programming you would have to declare how many decimal places a non-integer would have. So when new fangled programming languages came along that allowed the variable to hold any value and move the decimal place around they called it a float because that's what the decimal place can do.
 
I ain't no coder (though I did some C in 1994), but if you're struggling to find out what a "float" is, you're in for a rough ride trying to learn C#.
Do the types (bool, char, int, float, double) still refer to different bit / byte lengths? So if you want big numbers, you need to use double even if you're going to be working with integers?
 
Floating point variables can be a really complex subject - but generally the important thing is that an integer can't store a value like 9.5 only 9 or 10, while a float can be any value in between depending on the precision being used.

It is basically a number with a decimal point but there are limits to the precision (decimal places) - look up double floats, etc.
 
It all becomes clear when you do some simple division using the different data types and print the output using a range of different numbers.
 
Back
Top Bottom