FAQ Database Discussion Community

## Is there a way to show correct float value?

python,python-2.7,floating-point,division
Is there a way to show float value in Python 2 like Python 3 does? Code: text = "print('hello, world')" step = 100.0 / len(text) result = 0.0 for _ in text: result += step print result print step print result == 100.0 Python 2.7.9 100.0 4.7619047619 False Python 3.4.3...

## Making a randomly generated division sum that always results in a whole number?

division
I am currently making a random math quiz which generates random addition, subtraction, and multiplication fine. Those 3 are simple. I would like to know just how to make a randomly generated division question that always equals a whole number, using 2 int variables, num1 and num2 but I just...

## Fixed width div and float:right div not working

html,css,division
I cannot for the life of my find out why this technique isn't working. No matter what I do, the left div is 100% when it should adjust to the float:right div. .chat-container { background: black; height: 60px; } .chat-bar { height: 60px; width: 340px; float: right; background: rgba(255, 0,...

## Incorrect division result with double value

java,division
I have a problem doing a division. I have this chunk of code, where this operation must be 40.4239, but instead i have this result: 0.005595493389623997 I can understand the amount of decimals, I have to solve that with decimalFormat, but I cant understand this result... contTotal is 288975 in...

## How to divide a series of values in one array by a series of values in another array

java,arrays,division
I am a beginner in Java and would like to ask some help with a array problem I am having. I am trying to build a simple program that has two int type arrays with 5 integers in each array. I want to divide the length of integers in one...

## Implementing c binary division in o(1)

c,binary,division
I found this (slightly modified) code to implement division on unsigned numbers: #include <climits> #include <stdio.h> unsigned divide(unsigned dividend, unsigned divisor) { unsigned current = 1; unsigned answer=0; if ( divisor > dividend) return 0; if ( divisor == dividend) return 1; while (divisor <= dividend) { // this will...

## Division by 3 in Python

python,division,floor
I am new to Python and while experimenting with operators, I came across this: >>> 7.0 / 3 2.3333333333333335 Shouldn't the result be 2.3333333333333333 or maybe 2.3333333333333334. Why is it rounding the number in such a way? Also, with regard to floor division in Python 2.7 my results were: >>>...

## Accelerated C++ on quotients

c++,division,accelerated-c++
I am reading the book "Accelerated C++". In the details of chapter 2, a description of division between two numbers and extracting their quotient is provided: x / y Quotient of x and y . If both operands are integers, the implementation chooses whether to round toward zero or -...

## Why do I get wrong output?

java,output,division
I am very new to Java and am trying to write a simple code. Here is the description: Write a program that prompts the user for a number X. Print the numbers from 1 to X. However, in place of multiples of 4 print “qqqq”. In place of multiples of...

## Is divmod() faster than using the % and // operators?

python,performance,division,modulus,divmod
I remember from assembly that integer division instructions yield both the quotient and remainder. So, in python will the built-in divmod() function be better performance-wise than using the % and // operators (suppose of course one needs both the quotient and the remainder)? q, r = divmod(n, d) q, r...

## Division by zero warning when divisor is “0.0”

php,division
I'm reading data from a text file and performing some basic math. This is how things should work: // no warning, expected result N/A \$dividend = 100; \$divisor = 0.0; if (!empty(\$dividend) && !empty(\$divisor)) { \$quotient = \$dividend/\$divisor; } else { \$quotient = 'N/A'; } echo \$quotient; This is how...

## How to check if Number is Even or Odd and Greater than 100?

actionscript-3,division,flash-cs6,modulus
Hey guys so I am wondering if this is possible. So in my game I have it set up to where if they make a point the score goes up by 5. I implemented a multiplier in the game so if they dont get hit and continue making points then...

## C# Divide the values of one list by the values of the other to produce a new list

c#,list,listbox,division
I wish to divide the corresponding values of each list in order to produce a new list containing the divided results of each corresponding index in my two lists. Both my lists are 8 values long and are both int lists. I am currently creating two lists that are to...

## Bash Script division

linux,bash,scripting,division,operand
I'm a beginner in scripting. I have a temperature sensor which gives me temperature if I cat the file /sys/bus/w1/devices/28-000006c5772c/w1_slave. The output of the file looks like: 83 01 4b 46 7f ff 0d 10 66 t=24187 As you can see the temperature is t=24187 which I have to divide...

## integer division to float result [duplicate]

java,floating-point,division
This question already has an answer here: Fahrenheit to Celsius conversion 3 answers I have to divide two integers and get a float as result My Code: Float ws; int i = Client.getInstance().getUser().getGespielteSpiele() -Client.getInstance().getUser().getGewonneneSpiele(); int zahl1 = Client.getInstance().getUser().getGewonneneSpiele(); ws = new Float((zahl1 / i)); I check the values with...

## How to refine the result of a floating point division result?

math,floating-point,division,ieee-754
I have an an algorithm for calculating the floating point square root divide using the newton-raphson algorith. My results are not fully accurate and sometimes off by 1 ulp. I was wondering if there is a refinement algorithm for floating point division to get the final bits of accuracy. I...

## Div height 100% following two float divs inside

html,css,division
I want to arrange two divs horizontally inside a div. The two divs height flexible, because there is a table in it. A table can be filtered so the height sometime must be changed. I want the outside div can dynamically following two divs inside. I use height 100% for...

## How to get decimal remainder of two numbers divided?

c#,math,decimal,division
So I am trying to make a script where the user inputs the number of miles they need to travel and the miles per hour they are traveling and the script outputs the hours and minutes leftover that they must travel. I've been trying to use % to find the...

## Find all numbers only divisible by 3, 5 and 7

math,division
I was asked on an interview to find all numbers only divisible by 3, 5 and 7. I purposed we can make check like if (num%3==0 || num%5==0 || num%7==0) return true else return false. But in this case if we have 6 it will pass the test but its...

## How to divide list item by list item from another list using Python?

python,list,division
I would like to divide list items inside two lists. a = [[1, 0, 2], [0, 0, 0], [1], [1]] b = [[5, 6, 4], [6, 6, 6], [3], [3]] How can I divide a by b to obtain this output: c = [[0.2, 0, 0.5], [0, 0, 0], [0.333],...

## Calculating average spending (amount spent/person) in a particular month mysql

mysql,sql,math,sum,division
I have three tables in my database with schema: items (itemID: integer, description: string, price: integer) orders (orderID: integer, itemID: integer, aID: integer, customerID: integer, date: date) customers (customerID: integer, fName: string, lName: string) I need to calculate the average amount of money spent by ALL customers in a given...

## How to use two dimensional arrays, Inverses, and multiplication to get solutions to a given linear equation?

c,arrays,math,division
Given these equations: ax + by = c dx + ey = f #include<stdio.h> #include<stdlib.h> int main (void){ //Data float extra; float x[2]; float y[2]; float solution[2]; float coef[2][2]; printf("Give Numbers:\n"); scanf("%f %f %f %f %f %f" ,&coef[0][0], &coef[0][1], &solution[0], &coef[1][0], &coef[1][1], &solution[1]); // Create Determinant float det; det =...

## Child div not inlining inside parent div

html,css,css-float,inline,division
I must be doing something stupid or looking over something obvious, because no matter what I do I cannot get these three divs inline inside this parent. .stats { display: inline-block; margin-right: 6px; float: right; padding: 0; font-family: "Roboto" sans-serif; color: black; } .separator { background: rgba(47, 187, 255, 0);...

## What's wrong with the following arithmetic operation? C++ [duplicate]

c++,codeblocks,long-integer,division
This question already has an answer here: What is the behavior of integer division in C? 5 answers I'm just trying to do a simple arithmetic operation but it returns me the 0 value. Here's the code: main(){ long Population_A, Population_B; cin>>Population_A; cin>>Population_B; float Increase_A, Increase_B; Increase_A = (6*Population_A)/100;...

## Eigen vector matrix right division issue

c++,matrix,vector,division,eigen
I am trying to perform right division in c++ on a vector/matrix as is done in matlab with the / operator. More specifically, I am using eigen and the code snippet where I try to do the division is the following: #include <Eigen/Dense> // Do stuff // ... Vector3d instance;...

## Python 3, 5/2 when importing from module gives 2 and not 2.5

python,division
Im making a calculator program in python 3 and I have split the program into modules. I made a subtraction function in a module that just takes two numbers and divides with the normal / operator. However, it seems to be acting like / from python 2 and 5/2 gives...

## Calculating a percentage in SQL

sql,sql-server,count,division,percentage
I'm trying to calculate a percentage in SQL. I want to find out to get the percentage of output start with 'RT @' CREATE TABLE temp ([tweet] varchar(130)) ; INSERT INTO temp ([tweet]) VALUES ('WillyWonka'), ('Barbara'), ('JoanOfArcJoanArcadia'), ('LisaDLisa Diddle'), ('LisaDSkip Padington'), ('WillyNillySiil Stoinson'), ('RT @Barbara'), ('JoanOfArcJoanArcadia'), ('LisaDLisa Diddle'), ('RT @LisaDSkip...

## Matlab figure visualization

matlab,plot,division,figure,subplot
In Matlab, I would like to visualize the test results in a figure with several charts and text. The figure is divided into rows and colums: 3 rows and 5 colums. For better understanding, here a screenshot of the figure with a orange grid which shows the subplot division: Now...

## Literal vs variable with spaces on divide operator in Ruby

ruby,variables,division,literals
Let's say I have a literal Fixnum 1420028751000 and I want to convert using this: Time.at(1420028751000 / 1000) # => 2014-12-31 20:25:51 +0800 I can put spaces also, let's say I am beginner and my coding is bad: Time.at(1420028751000 / 1000) Time.at(1420028751000 /1000) All these work fine and give me...

## Perform integer division using multiplication

assembly,optimization,bit-manipulation,division,multiplication
Looking at x86 assembly produced by a compiler, I noticed that (unsigned) integer divisions are sometimes implemented as integer multiplications. These optimizations seem to follow the form value / n => (value * ((0xFFFFFFFF / n) + 1)) / 0x100000000 For example, performing a division by 9: 12345678 / 9...

## Dividing integers by floats resulting in proportional integers

algorithm,integer,division,integer-division
Recently I've came across a hard problem solving while doing a project. And I'd like to ask you guys for a solution / algorithm to solve it, because I'm really struggling to think about a clever idea to do so. I have an arbitrary number of floats: f1, f2, ...,...

## EXC_ARITHMETIC Error With Nonzero Denominator - XCode

c,xcode,division
Usually, when I get an EXC_ARITHMETIC error, it means I divided by zero, which makes sense to me. However, this time I have no idea what is going on. Here is a function that is being called rather frequently: GP_TYPE GP_NodeFunction_Divide(GP_Node* node, GP_Mem* mem, void* data){ /* These are just...