Home > Mobile >  What is a floating number and its purpose in terms of theory
What is a floating number and its purpose in terms of theory

Time:11-27

I am just learning python and making a calculator and the tutorial says float instead of int. what is a floating number

Why not just use int

CodePudding user response:

Floats, contrary to int or integer data types, can store numerical data with much more precision. Integers lose information regarding to the mantissa or decimal portion of the number. So in applications where precision is required, we use float data type instead of int.

CodePudding user response:

welcome to Stackoverflow!

This is a question on which you can dive deep, and I would absolutely google this. For example, the Wikipedia page on this will already give you a bunch of information.

Now, in order not to overwhelm you with a too much information, we can answer your question without too many details:

A float is a type with which you can represent decimal numbers (numbers with a comma in there, for example 0.5). An int is a type with which you can only represent integers (1, 2, 50, ...).

Don't hesitate to google around for more info!

CodePudding user response:

A float is a number with numbers after decimal points, for example 12.56 . It can also be called a real.

An integer is a whole number eg 12.

If you use an integer in a calculator, then you wouldn't be able to calculate with anything other than whole numbers.

for example using int is fine if you do 12 12. However, if you enter 12.56 12.56, then you will get an error, as the int function assumes that the user enters a whole number

  • Related