Questions tagged [divide]

Separate or be separated into parts

Separate or be separated into parts

688 questions
17
votes
4 answers

objective-c divide always returns 0

Something really weird is happening. float p1 = (6 / 100); NSLog(@"p1 = %f", p1); With those two lines of code I get the following output: p1 = 0.000000 Why is a simple devide with static numbers not working! I have so much work to do to deal with…
Paul Hart
  • 171
  • 1
  • 1
  • 3
16
votes
7 answers

Odd behaviors when dividing doubles in Java

When I divide 317 by 219 in Java using doubles I get 1. For example: double b = 317/219; System.out.println(b); Output is: 1. Is this because it is a recurring decimal? Have had to use BigDecimal instead which is annoying.
Joe
  • 165
  • 1
  • 1
  • 5
15
votes
9 answers

How to divide a list into n equal parts, python

Given (any) list of words lst I should divide it into 10 equal parts. x = len(lst)/10 how to give these parts variable names? In the output I need 10 variables (part1, part2... part10) with x number of words in it.
Gusto
  • 1,483
  • 9
  • 23
  • 34
15
votes
1 answer

How to select duplicate rows with pandas?

I have a dataframe like this: import pandas as pd dic = {'A':[100,200,250,300], 'B':['ci','ci','po','pa'], 'C':['s','t','p','w']} df = pd.DataFrame(dic) My goal is to separate the row in 2 dataframes: df1 = contains all the rows that…
Federico Gentile
  • 5,650
  • 10
  • 47
  • 102
15
votes
10 answers

Can anyone explain why '>>2' shift means 'divided by 4' in C codes?

I know and understand the result. For example:
7 (decimal) = 00000111 (binary)
and 7 >> 2 = 00000001 (binary)
00000001 (binary) is same as 7 / 4 = 1
So 7 >> 2 = 7 / 4

But I'd like to know how this logic was created.…
user573566
  • 509
  • 2
  • 6
  • 9
14
votes
7 answers

Where can I find soft-multiply and divide algorithms?

I'm working on a micro-controller without hardware multiply and divide. I need to cook up software algorithms for these basic operations that are a nice balance of compact size and efficiency. My C compiler port will employ these algos, not the…
srking
  • 4,512
  • 1
  • 30
  • 46
12
votes
5 answers

Divide count by count(*) in SQL Server

Here is my query : SELECT COUNT(*) AS total, COUNT(CASE WHEN t.id IS NULL THEN 1 END) AS nb_null, COUNT(CASE WHEN t.id IS NOT NULL THEN 1 END) AS nb_not_null FROM table t Is it possible to divide a field by an alias? : SELECT …
Vincent Ducroquet
  • 864
  • 4
  • 14
  • 24
10
votes
3 answers

How do I apply a function with multiple parameters using `cellfun` (MATLAB)?

Using cellfun, how do I apply a function to all the cells created by the mat2cell function? My function is defined in another file, here it is referred to by myFunc. This function takes two arguments, which should be a cell and an integer. e.g.…
petehallw
  • 1,014
  • 6
  • 21
  • 49
10
votes
3 answers

divide by count result in mysql

SELECT COUNT(*) FROM Table1 WHERE user = "carl" AND ans = "yes" then i want to divide the output of this query to another query, for example the output is 10. so it will be like: 10 / SELECT COUNT(*) From Table1 WHERE user = "carl" How is the…
9
votes
5 answers

C#: divide an int by 100

How do I divide an int by 100? eg: int x = 32894; int y = 32894 / 100; Why does this result in y being 328 and not 328.94?
Craig Johnston
  • 7,467
  • 16
  • 40
  • 47
9
votes
3 answers

How to divide each column of pandas Dataframe by a Series?

I have a pandas dataframe in which I want to divide each column by the same data series values for each row. Each column and the data series have the same length. The data series has only float numbers but some cells in the dataframe have NaNs. I…
Rolf12
  • 701
  • 1
  • 6
  • 20
9
votes
2 answers

Correct sums with dividing sums, countering rounding errors

Web app coded in PHP with a MySQL database. I have a system which calculates different costs for a number of people when splitting a cost. For example Person A buys something for 10 and Persons B, C, and D should split the cost. The system should…
Per Enström
  • 902
  • 8
  • 33
8
votes
2 answers

How to divide a number of columns by one column?

I have the below dataset: Monday Tuesday Wednesday Friday Saturday Total 2 3 4 5 6 20 3 6 7 5 1 22 I am doing the below: I need to divide first row: 2/20, 3/20, 4/20, 5/20, 6/20 And on…
paploo
  • 153
  • 1
  • 2
  • 5
8
votes
11 answers

Split String into groups with specific length

How can I split the given String in Swift into groups with given length, reading from right to left? For example, I have string 123456789 and group length of 3. The the string should be divided into 3 groups: 123, 456, 789. String 1234567 will be…
katleta3000
  • 2,484
  • 1
  • 18
  • 23
7
votes
2 answers

Raku: Attempt to divide by zero when coercing Rational to Str

I am crunching large amounts of data without a hitch until I added more data. The results are written to file as strings, but I received this error message and I am unable to find programming error after combing my codes for 2 days; my codes have…
lisprogtor
  • 5,677
  • 11
  • 17
1
2
3
45 46