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
65
votes
10 answers

Make division by zero equal to zero

How can I ignore ZeroDivisionError and make n / 0 == 0?
octosquidopus
  • 3,517
  • 8
  • 35
  • 53
63
votes
7 answers

negative zero in python

I encountered negative zero in output from python; it's created for example as follows: k = 0.0 print(-k) The output will be -0.0. However, when I compare the -k to 0.0 for equality, it yields True. Is there any difference between 0.0 and -0.0 (I…
max
  • 49,282
  • 56
  • 208
  • 355
44
votes
4 answers

Pad python floats

I want to pad some percentage values so that there are always 3 units before the decimal place. With ints I could use '%03d' - is there an equivalent for floats? '%.3f' works for after the decimal place but '%03f' does nothing.
hoju
  • 28,392
  • 37
  • 134
  • 178
43
votes
7 answers

Equals operator for zeros (BigDecimal / Double) in Java

A few interesting observations w.r.t equals operator on 0 and 0.0 new Double(0.0).equals(0) returns false, while new Double(0.0).equals(0.0) returns true. BigDecimal.ZERO.equals(BigDecimal.valueOf(0.0)) returns false, while…
Manish Mulani
  • 7,125
  • 9
  • 43
  • 45
40
votes
7 answers

Changing a SUM returned NULL to zero

I have a stored procedure as follows: CREATE PROC [dbo].[Incidents] (@SiteName varchar(200)) AS SELECT ( SELECT SUM(i.Logged) FROM tbl_Sites s INNER JOIN tbl_Incidents i ON s.Location = i.Location WHERE s.Sites =…
Icementhols
  • 653
  • 1
  • 9
  • 11
38
votes
13 answers

How to remove rows with any zero value

I have a problem to solve how to remove rows with a Zero value in R. In others hand, I can use na.omit() to delete all the NA values or use complete.cases() to delete rows that contains NA values. Is there anyone know how to remove rows with a Zero…
YougyZ
  • 509
  • 1
  • 4
  • 10
37
votes
2 answers

How to fill a matrix with zero (0)

I need to fill matrix distances with 0. How can I do this? distances <- matrix(1:25, nrow=5, ncol=5) apply(distances, c(1, 2), function(x) 0)
Klausos Klausos
  • 15,308
  • 51
  • 135
  • 217
37
votes
2 answers

How set 0 with MAX function when it is NULL?

I would like to understand how to set 0 value of the attribute when it is NULL with MAX function. For example: Name columns: number - date Values: 10 - 2012-04-04 11 - 2012-04-04 12 - 2012-04-04 13 - 2012-04-15 14 - 2012-06-21 1 -…
Donovant
  • 3,091
  • 8
  • 40
  • 68
36
votes
2 answers

zerofill a integer php

How would I go about 'zero filling' an integer? ie 1 becomes 0001 40 becomes 0040 174 becomes 0174
dotty
  • 40,405
  • 66
  • 150
  • 195
34
votes
1 answer

Oracle, adding leading zeros to string (not number)

I am using Oracle (work space is TOAD) and I need to make my strings that if they are shorted then 10 characters then add leading zeros to make them all 10 digit strings. For example if I have a string like this: '12H89' need to be '0000012H89' or…
Ovi
  • 2,459
  • 9
  • 50
  • 72
33
votes
7 answers

Removing Trailing Zeros in Python

I need to find a way to convert the following strings in python: 0.000 => 0 0 => 0 123.45000 => 123.45 0000 => 0 123.4506780 => 123.450678 and so forth. I tried .rstrip('0').rstrip('.'), but that doesn't work if the input…
Raiders
  • 361
  • 1
  • 3
  • 5
32
votes
2 answers

How to replace nulls with zeros in postgresql crosstabs

I've a product table with product_id and 100+ attributes. The product_id is text whereas the attribute columns are integer, i.e. 1 if the attribute exists. When the Postgresql crosstab is run, non-matching atrributes return null values. How do I…
Mike
  • 439
  • 1
  • 6
  • 10
32
votes
12 answers

'0' as a string with empty() in PHP

I want a 0 to be considered as an integer and a '0' to be considered as a string, but empty() considers the '0' as a string in the example below, $var = '0'; // Evaluates to true because $var is empty if (empty($var)) { echo '$var is…
Run
  • 54,938
  • 169
  • 450
  • 748
31
votes
4 answers

Size of zero pixels in CSS with or without 'px' suffix?

Googling for the answer to this question has proven difficult so I figured somebody here should know. Within CSS, I've seen zero pixels declared as simply '0' yet also as '0px'. mystyle { width: 0; } anotherstyle { width: 0px; } The minor problem…
Sparky
  • 98,165
  • 25
  • 199
  • 285
29
votes
7 answers

PHP remove first zeros

Want to remove all 0 placed at the beginning of some variable. Some options: if $var = 0002, we should strip first 000 ($var = 2) if var = 0203410 we should remove first 0 ($var = 203410) if var = 20000 - do nothing ($var = 20000) What is the…
James
  • 42,081
  • 53
  • 136
  • 161
1
2
3
70 71