Most voted "float" questions
Float is a type of primitive data that represents a floating point of simple precision at 32 bits. Use this tag for questions that directly involve a given float (such as rounding, converting, formatting, etc.), DO NOT USE simply because it contains a float in your code.
Learn more…128 questions
Sort by count of
-
56
votes4
answers3125
viewsPrecise math division
In Windows calculator: 9/3,0001 = 2,999... In my program: 9/3,0001 = 3; I would like to get that level of accuracy using C. Watch excerpts from my program: double op(double num1, double num2, char…
-
46
votes2
answers45560
viewsWhat is the correct way to use the float, double and decimal types?
Since college I can’t understand the real difference between the type DOUBLE and FLOAT, I ended up meeting the guy DECIMAL which also treats real values. About the type DECIMAL, found the following…
characteristic-language float language-independent decimal doubleasked 7 years, 4 months ago Marconi 17,287 -
25
votes5
answers80372
viewsHow to "round" a float in Python?
I have this sum: total = 0.1 + 0.2 print total #retorna 0.30000000000000004 How would I "round" the decimal places and return only the number of places summed? Example: totalA = 0.1 + 0.2…
-
20
votes5
answers140931
viewsHow to limit decimal numbers in Python?
How do I format the number of decimals of a decimal number in Python? For example, I want to display only two decimal places of the following number: numero_decimal = 3.141592653589793 How could I…
-
17
votes1
answer85227
viewsJavascript generating float with multiple decimals
When creating an order calculation system (quantity x value) I realized that in some cases when adding broken values Javascript returns numbers with many other decimal places more than expected.…
-
15
votes2
answers2992
viewsDecimal places of the float
I am developing an application to control product sales. However, sometimes the added value of reports does not beat decimal places. Gives small differences. How to make the float stop giving these…
-
13
votes3
answers799
viewsFloats module in PHP returns integers?
How do I get the rest of the division (operation module %) with decimal places when using a divisor or dividend float? Example: echo 5 % 3; // imprime 2 como é esperado echo 5.6 % 3; // imprime 2…
-
10
votes2
answers390
viewsFloat with PHP precision
I am bringing from the database the sum of the values and as a result it returns me as the example below: 6.3285714285714 I wish he’d stay that way: 6.32 I’ve tried the ceil() and the round(), but…
-
9
votes2
answers1126
viewsWhat kind of data (double, float) should I use when representing a temperature?
My question is regarding the use of Double and of Float in Java exercises when having to declare a temperature (Celsius scale). Which one should I use in this case? I declared as Double, but the…
-
8
votes1
answer162
viewsWhat is the need to use the suffix "f" in a numerical constant in C?
It is necessary to add f at a value float within the parameters of a if? Example: if (a == 2.5f && a > 2.0f) {}…
-
7
votes2
answers1833
viewsError: Object of type 'float' has on Len
I was thrashing simple operations on the Python interpreter, and the following command made me curious: >>> b = 3.12; len(b) With the following error: Traceback (Most recent call last):…
-
7
votes2
answers11799
viewsWhat does float("Nan") and float("inf") mean in Python?
I’ve seen a code like this: def _min(*args): res = float('inf') for value in args: if value < res: res = value return res I would like to know what is a float("inf") and a float("Nan").…
-
6
votes4
answers11111
viewsConverting float to char array in C/C++
I recently took a test and there was a question that asked for a number like 123.456 was shown as 321.456. I thought the best solution would be to convert this to an array of char and then create an…
-
6
votes1
answer11317
viewsFloat rounded in C
I need to return a value float with 1 decimal place, but is returning with the rounded value. I have the following code: float n1 = 4; float n2 = 9; float total = n2 / n1 ; printf("Media: %.1f ",…
-
6
votes2
answers162
viewsCentralize Divs responsibly
Next, I always looked for a solution to this type of problem, but never found. I have the following codes. <style> .allboxframes { margin: 0 auto; max-width: 100%; } .box-frames { margin: 0…
-
5
votes1
answer104
viewsARM-M4 Math Operations Lock When PWM Interrupt Is On
When I turn off the timer overflow interruption from PWM (+- 15Khz) operations occur normally. But when it is turned on the processor gets lost in floating point operations. I follow by the debug in…
-
5
votes1
answer12643
viewscan’t Multiply Sequence by non-int of type 'float'
Error: can’t Multiply Sequence by non-int of type 'float' I am facing this error, I know it involves variable types, but I do not know how to make the entry receive a float type value…
-
4
votes2
answers2761
viewsPHP value rounding error
I have a problem, after assigning to a variable a float value as below, 4.85, after multiplying by 100, 48500 and when I print out the value of 00000000484. $variavel = 4.85; $valor = $variavel *…
-
4
votes1
answer488
viewsDifferent numbers become equal after conversion with doubleval
I have 2 values 4850.00 and 4850.01 When I set 2 variables manually with these values and compare using if, returns me different (OK). But in an ERP system I develop I receive 2 values via AJAX.…
-
4
votes4
answers5300
viewsHow to fix the number of numeric characters in a float?
I wrote a simple code where at the end of a precise mathematical operation the result would be seven numeric characters regardless of where the point is. Unfortunately I can only adjust the…
-
4
votes1
answer77
viewsWhy does the Math.toRadians method return an inaccurate value?
I was programming a method in which I needed to convert a value from degrees to radians and I wondered if this conversion no longer existed in Java. Searching the Internet I discovered the method…
-
3
votes2
answers208
viewsI cannot get return of floats through expressions
When I try to give print(6/10) get a int (0) instead of a float (0.6) And if I give type(6/10) returns int. I’m following this tutorial and doing exactly the same steps in both pyCharm and IDLE,…
-
3
votes1
answer3228
viewsProblems with entering data in the float field in MYSQL
I have a problem when inserting a value in a field in the table, this field is like float(15,6). I ran an Insert here INSERT INTO valores (valor) VALUES ('1160.480000'); Why it inserts the value as…
-
3
votes2
answers2391
viewsIn PHP, is there a difference between Double and Float?
In some programming languages, Float and Double, although similar, are not the same. But apparently in PHP there is no difference between these two types. Is there any special reason for this?…
-
3
votes1
answer61
viewsFloat to Byte Array conversion
How can I be performing the conversion of float or integer (if possible) for a array byte in Java. Say: float x=180 Theoretically you would need to create 1 array 2 position bytes. Is there any way…
-
3
votes2
answers3734
viewsLimit decimal places float c#
I would like to show the mediadesp and mediareceit with 2 decimal places after the comma. private void MediaReceitaseDespesas() { /* ----TOTAL / QTDE DE VALORES INFORMADOS----*/ mediadesp = somadesp…
-
3
votes1
answer355
viewsParsing columns of numbers from a CSV file in C
Hello, Good Night I am with a file . CSV simple, containing only two columns, separated by comma and by the new line, as an example: 0.001,-9.623 0.098,2.540 1.000,-1.002 And I need to separate them…
-
3
votes3
answers1075
viewsOrganize Divs into blocks over each other?
I would like to organize my Ivs in column form, but not side by side, but rather on top of each other. Usually when using float: left or display: inline-block the elements are placed side by side up…
-
3
votes2
answers121
viewsUsing float to check overflow in unsigned long int
Hello, all right? Please review this code: #define max 4294967295 unsigned long int collatz(unsigned long int n, unsigned long int passos, float *maiorN) { float overflow = 3 * n + 1; if (n == 1)…
-
3
votes1
answer107
viewsDivisions miscalculating in C
#include <stdio.h> int main() { double A, B; double MEDIA; scanf("%f", &A); scanf("%f", &B); MEDIA = (A + B)/2; printf("MEDIA = %5f", MEDIA); return 0; } In this program I have already…
-
3
votes0
answers46
viewsFloat Sum. Workaround for the Java Script 0.3 billion 0004 error
I’m making a list of exercises about Java Script and the question where you ask 05) Dealing with numbers in Javascript can give you a lot of headache. Have you seen what happens when you do the…
-
2
votes2
answers1749
viewsTurn string into number
I have a problem that for many are simple, I have a code that takes the value of a input of the kind hidden and when I pick up this amount, I add +1, ie if the value is 3 it add +1 and have to stay…
-
2
votes2
answers471
viewsDecrease float accuracy in Javascript?
How to decrease the decimals of a float number in javascript? For example, I want 3.3333333333 become in 3.34. What is the simplest way to do this in javascript? I tried functions like Math.ceil,…
-
2
votes2
answers205
viewsTypeerror: 'float' Object has no attribute 'getitem'
First, as soon as the mouse is clicked, the shooting angle ( that is the same angle of the player) is stored in the bullets_array list. Second, it is given speed to the shot through the 'cos' and…
-
2
votes1
answer254
viewsJavascript function with Nan error
This function is returning error: Nan, to convert again to text. function floatToMoneyText(value) { var text = (value < 1 ? "0" : " ") + Math.floor(value * 100); text = "R$ " + text; return…
-
2
votes1
answer1596
viewsWhat is the maximum of decimal places allowed in the PHP float?
I was using Psysh to test with numbers like float. I noticed that, after a certain amount, it begins to limit the decimal places. Example: $float = 1.1234567891011121314 echo $float; //…
-
2
votes1
answer113
viewsError in variable value
I am with the following doubt, I have to add a set of values that are set as string's, so I had to convert to float, I used the function str_replace(), only that when testing the variable with the…
-
2
votes2
answers659
viewsProblem with float python (Uri 1098)
I’m trying to solve this problem and when I execute the code, at a certain point it stops working correctly. I think it’s because of rounding, but when that part is removed, the code runs to…
-
2
votes2
answers10163
viewsHow to make the rest of the division of a float by a number in c?
I am beginner in programming in c, I have here a problem the exercise and calculate the average of the odd in a matrix that receives real numbers. However, I’m having the following mistake: error:…
-
2
votes2
answers849
viewsHow to pass a float without loss of value to an integer?
I have a float variable that can contain any number in it, I need to test if it fits an integer without losing values. I thought to use some test to see if the numbers after the comma are 0’s or…
-
2
votes1
answer493
viewsHow can I set a range for a float?
Trying to implement Newton’s method for finding roots in polynomials, using Horner’s method. n=len(a)-1 print("k\t a\t x\t px") for k in range (0, iterMax): b=a[0] c=b for i in range (n-1,1):…
-
2
votes2
answers3142
viewsHow can I print the fifth part of a real number?
How could I print the fifth (index 4 from the dot) part of a real number without using libraries or a "complex" code for initial chapters. Make a program that reads a real number, and print the…
-
2
votes1
answer82
viewsWhy does subtraction of float by float give unexpected result?
I spent a good time to solve this problem on my system. Solved? I did, but at some point it’s working (the subtraction value) = -0.0 and I have to give . replace('-', '') to show the user a positive…
-
2
votes1
answer235
viewsAccuracy of float64
Why Go when performing the calculation: (1 * 0.09) + 0.36 returns a float64 in the following format 0.44999999999999996? I’m trying to make comparisons with tests and the calculation should be 0.45…
-
2
votes2
answers2032
views -
2
votes2
answers103
viewsUnexpected result
I wish to carry out the division of two integers and have as a result a floating point value. The following code works normally: #include <stdio.h> float divInts(int x, int y) {…
-
2
votes1
answer1132
viewsConvert Float to Python Binary
I’m studying the IEEE 754 standard, and I should create a new 16-bit method. This function is to convert the mantissa that is already in format 1,xxx*2 yyy What may have gone wrong in this code,…
-
2
votes1
answer328
viewsAfter clear:Both, float div does not align correctly
I’m making a responsive website and I’m using "float" and "clear: Both" to put the Ivs in their places. But after using "clear: Both", the "div6" does not align correctly on the right side. To…
-
2
votes2
answers98
viewsWarning: format '%f' expectts a matching 'double' argument (en)(en)
My first post here and I would like to know, because when I compile my code it gives an error saying the format %f expecting a double, whereas the f is used to float and the variable I’m putting is…
-
2
votes0
answers52
viewsWhy is "c_float()" generating incorrect values?
I am creating a program in Python - using the library ctypes - to read and write values in memory, and I want to be accurate in the size of the data to be read and written. In this case, if the…