Questions tagged [negative-number]

A negative number is a number that is less than 0. It is signified by a preceding hyphen (i.e. -12,345).

This tag should be used for any questions dealing specifically with negative numbers.

599 questions
4
votes
1 answer

MySQL Data Type to Store Negative Number

I have a rating system that ranges from -1 to 5 through 0. So i need to store the following values -1 0 1 2 3 4 5 Which is the best data type considering i want to fetch a total count of each value (not sum) ?
Harsha M V
  • 54,075
  • 125
  • 354
  • 529
4
votes
1 answer

Dividing negative numbers with floordiv in python

I'm confused by the nature of integer division with // or floordiv with negative numbers in python. >>> -5 // 2 -3 >>> int(-5/2) -2 Why would floordiv() round down to -3? I thought integer division was supposed to simply drop (or lack) the…
Kevin Lee
  • 89
  • 1
  • 6
4
votes
3 answers

trunc and round function in sql

Is trunc and round the same with negative arguments? SQL> select round(123456.76,-4) from dual; ROUND(123456.76,-4) ------------------- 120000 SQL> select trunc(123456.76,-4) from dual; …
lakshganga
  • 2,355
  • 6
  • 21
  • 22
3
votes
2 answers

JTextArea only with numbers, but allowing negative values

I have a JTextArea which only has to accept numbers. This is my code: DocumentFilter onlyNumberFilter = new AxisJTextFilter(); final JTextArea areaTextoXMin = new JTextArea(String.valueOf(xMin)); …
Roman Rdgz
  • 12,836
  • 41
  • 131
  • 207
3
votes
5 answers

Python Calculator Divide by Zero/Sqrting a Neg. Int. crashing program

Alright, I'm doing this for a project and whenever I attempt to have it divide by zero or square root a negative number that program closes out. I've attempted to find something I can insert into the code to make it display a message and then prompt…
Sam
  • 75
  • 2
  • 7
3
votes
2 answers

Remove minus sign from Woocommerce negative fees displayed amount

I am developing a booking system in which the client wants only to take a USD 50 deposit and to negotiate the remaining amount separately. In order to achieve this I have used the following code to update the total price to USD 50 and to show the…
Disura
  • 48
  • 5
3
votes
2 answers

How to think about Python's negative number bitwise operations?

I find it quite difficult to think about Python (and Python3)'s infinite precision negative numbers and bitwise operations. It is not 32-bit or 64-bit. The 1s at the left can be thought of as "infinitely many". It is not very definite, which is…
3
votes
2 answers

Swift Double.remainder(dividingBy:) returning negative value

let num = 32.0 Double(num).remainder(dividingBy: 12.0) I'm getting -4?..instead of 8.0...it's subtracting 12.0 from 8.0 how do i fix this?
caa5042
  • 166
  • 3
  • 16
3
votes
2 answers

Timing a VBA code returned a negative time

I ran some code in VBA as per https://www.thespreadsheetguru.com/the-code-vault/2015/1/28/vba-calculate-macro-run-time and had a return of a negative value: -20439 seconds Does anyone know why? It actually ran for ~ 18hrs (1500 - 0900 next…
frank
  • 3,036
  • 7
  • 33
  • 65
3
votes
1 answer

Negative bounds slice

I have two n-length tuples and I need to check whether all the elements in the same position are the same except for the element in position w. This is what I wrote: if all(tup1[i] == tup2[i] for i in xrange(n) if i != w): ... In order to avoid…
Pigna
  • 2,792
  • 5
  • 29
  • 51
3
votes
2 answers

Embedded division with negative numbers

In all my years of embedded programming, I've generally never needed to work with negative numbers. It's crazy, but they just don't come up very often in my line of work. I'm currently dealing with a sensor reading that can be positive or negative…
Jeff Lamb
  • 5,755
  • 4
  • 37
  • 54
3
votes
3 answers

C modulus returning negative number

I have data type unsigned __int128 data; so I don't think this is a type issue, but I have no idea why it is occuring #include int main(int argc, char *argv[]) { unsigned __int128 z = 1911602146; unsigned __int128 n =…
Kendall Weihe
  • 2,021
  • 4
  • 27
  • 53
3
votes
1 answer

Allow numbers in regex including the negative

I have written this regex to remove any thing which is not number. var dataTest = data.replace(/[^0-9]/gi, ''); It converts "abc123xyz" to "123" However now i want to cover negative numbers also :- var dataTest =…
Panther
  • 3,312
  • 9
  • 27
  • 50
3
votes
2 answers

Accessing an element of an array through negative indexes

I want to access contents of an array by arbitrary indexes. Lets say we have an array with three elements in it. The modulo comes in handy here and solves the problem for any positive integer perfectly: var arr = array['foo', 'bar', 'foobar']; var…
lilly
  • 297
  • 1
  • 2
  • 6
3
votes
4 answers

Array construction and negative numbers

I was implementing a routing algorithm in javascript, but when I assign a negative one variable in the array gives me this error: invalid array length. var node = new Array() node[0] = new Array(6,7) node[1] = new Array(5,-4,8) node[2] = new…
zizzamia
  • 241
  • 3
  • 9