Questions tagged [zero]

Zero is a unique number and along with 1 is one of the two binary numbers. Zero plays an important role in Mathematics and Computing. This Tag is for discussions of zero within various programming languages.

Zero is a unique number and along with 1 is one of the two binary numbers. Zero plays an important role in Mathematics and Computing. This Tag is for discussions of zero within various programming languages.

1060 questions
348
votes
3 answers

Is 0 a decimal literal or an octal literal?

Zero is always zero, so it doesn't matter. But in a recent discussion with a friend he said that octal literals are almost unused today.† Then it dawned upon me that actually almost all integer literals in my code are octal, namely 0. Is 0 an octal…
Yakov Galka
  • 70,775
  • 16
  • 139
  • 220
254
votes
6 answers

Check if bash variable equals 0

I have a bash variable depth and I would like to test if it equals 0. In case yes, I want to stop executing of script. So far I have: zero=0; if [ $depth -eq $zero ]; then echo "false"; exit; fi Unfortunately, this leads to: [: -eq: unary…
Perlnika
  • 4,796
  • 8
  • 36
  • 47
253
votes
3 answers

PHP prepend leading zero before single digit number, on-the-fly

PHP - Is there a quick, on-the-fly method to test for a single character string, then prepend a leading zero? Example: $year = 11; $month = 4; $stamp = $year.add_single_zero_if_needed($month); // Imaginary function echo $stamp; // 1104
Ben
  • 54,723
  • 49
  • 178
  • 224
111
votes
17 answers

Remove/ truncate leading zeros by javascript/jquery

Suggest solution for removing or truncating leading zeros from number(any string) by javascript,jquery.
Somnath Muluk
  • 55,015
  • 38
  • 216
  • 226
110
votes
13 answers

Nullable types: better way to check for null or zero in c#

I'm working on a project where i find i'm checking for the following in many, many places: if(item.Rate == 0 || item.Rate == null) { } more as a curiousity than anything, what's the best way to check for both cases? I've added a helper method which…
nailitdown
  • 7,868
  • 11
  • 36
  • 37
110
votes
10 answers

Is it safe to check floating point values for equality to 0?

I know you can't rely on equality between double or decimal type values normally, but I'm wondering if 0 is a special case. While I can understand imprecisions between 0.00000000000001 and 0.00000000000002, 0 itself seems pretty hard to mess up…
Gene Roberts
  • 2,192
  • 3
  • 17
  • 16
102
votes
12 answers

'property: 0' or 'property: 0px' in CSS?

I've seen this notation used a lot, and I was wondering, is there is any notable difference between these two notations? element#id { property: 0; } and element#id { property: 0px; } I use property: 0px; all the time, as I find it cleaner…
Blender
  • 289,723
  • 53
  • 439
  • 496
102
votes
13 answers

Fastest way to zero out a 2d array in C?

I want to repeatedly zero a large 2d array in C. This is what I do at the moment: // Array of size n * m, where n may not equal m for(j = 0; j < n; j++) { for(i = 0; i < m; i++) { array[i][j] = 0; } } I've tried using…
Eddy
  • 6,661
  • 21
  • 58
  • 71
94
votes
4 answers

How to create a numeric vector of zero length in R

I wonder, how can I create a numeric zero-length vector in R?
Surjya Narayana Padhi
  • 7,741
  • 25
  • 81
  • 130
93
votes
7 answers

Is it possible to differentiate between 0 and -0?

I know that the integer values 0 and -0 are essentially the same. But, I am wondering if it is possible to differentiate between them. For example, how do I know if a variable was assigned -0? bool IsNegative(int num) { // How ? } int num =…
Filip Minx
  • 2,438
  • 1
  • 17
  • 32
80
votes
8 answers

How do I check if a zero is positive or negative?

Is it possible to check if a float is a positive zero (0.0) or a negative zero (-0.0)? I've converted the float to a String and checked if the first char is a '-', but are there any other ways?
e4lime
  • 960
  • 1
  • 6
  • 11
78
votes
4 answers

Why do floating-point numbers have signed zeros?

Why do doubles have -0 as well as +0? What is the background and significance?
Ken Russell
  • 2,348
  • 5
  • 24
  • 39
76
votes
3 answers

How to remove trailing zeros from a double

For example I need 5.0 to become 5, or 4.3000 to become 4.3.
Wrath
  • 825
  • 1
  • 6
  • 6
74
votes
5 answers

Is NULL always zero in C?

I was interviewing a guy for a mid-level software engineering position yesterday, and he mentioned that in C, NULL is not always zero and that he had seen implementations of C where NULL is not zero. I find this highly suspect, but I want to be…
chi42
  • 925
  • 1
  • 7
  • 8
72
votes
6 answers

Why is JSON invalid if an integer begins with a leading zero?

I'm importing some JSON files into my Parse.com project, and I keep getting the error "invalid key:value pair". It states that there is an unexpected "8". Here's an example of my JSON: } "Manufacturer":"Manufacturer", "Model":"THIS IS A STRING", …
DJSrA
  • 797
  • 1
  • 5
  • 10
1
2 3
70 71