**Novo curso!**Todo programador deveria aprender

**IA generativa!**

+ 2

# Why do you use "float" in the code?

5 Respostas

+ 5

I avoid using float or double by doing my math with integers. However, there exists problems that require numbers between my nice integers such as drawing a circle or calculating interest on money. For those types of problems, float or double is perfect.
I'd use double unless you are sure that your range and number of digits needed for precision are small enough that float can maintain your numbers. For example, managing a normal US checkbook. Our numbers tend to run between $99,999.99 down to $-99,999.99. These numbers fit perfectly in floats.

+ 2

If you're asking about using floats in general, they're basically just used for holding numbers with a decimal point after, like 5.6 or 2.71. It's better to use floats while calculating equations that require division or more complex calculations to get a more accurate result.
d:

+ 1

NEVER USE FLOATS OR DOUBLES FOR ACCOUNTING!
Floating point representation is not accurate and can lead to inaccuracies, which you really don't want when you handle money.
For money always use integers and calculate in cents.
https://stackoverflow.com/questions/3730019/why-not-use-double-or-float-to-represent-currency/

+ 1

If you want a mathematical calculation and the numbers are float or double, the result should be float or double to be precise. Beware of the range.

+ 1

A Float is expressed a number as fractional value as 1.00, 2.00, 3.00, 1.5, 1.50, 1.75, 1.83, 1.333333333333 etc.
An integer means full value,it has no fraction,so it's expressed as 1, 2, 3, 4, 5, 6, 7 8, ...100 etc.
A integer can convert into float and this float is expressed as 1 to 1.0, or 1.00
A float can convert into integer by omitting It's fractional part as 1.333333 to 1, 2.75 to 2
More about Float
https://www.sololearn.com/learn/JUMP_LINK__&&__Python__&&__JUMP_LINK/2272/
[Prabhat Thakir ]
A floating point number is a extension of an older format ,called fixed point numbers.A fixed point number. would store a fixed number of digits before and after the decimal point (in binary).for example ,+1110101.00001000 is an example of a 16 bit fixed point number in 7.8 format(one bit is spent on sign).
The term double is short for "double precision floating point number ".it literally means that twice as many as bits are used in storing it as a regular floating point number.on a typical modern machines,floats are 32 bits( 1 but for sign,8bits for exponent,23 bits for value),while doubles are 64 bits(1 for the sign,11 bits for exponent and 52 bits for the value).