zero

php: '0' as a string with empty()

不问归期 提交于 2019-11-26 21:08:52
问题 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 empty'; } how can I 'make' empty() to take '0's as strings? thanks. 回答1: You cannot make it. That is how it was designed. Instead you can write an and statement to test: if (empty($var) && $var !== '0') { echo $var . ' is empty'; } You could use isset , unless of

What does an integer that has zero in front of it mean and how can I print it?

*爱你&永不变心* 提交于 2019-11-26 21:06:37
class test{ public static void main(String args[]){ int a = 011; System.out.println(a); } } Why I am getting 9 as output instead of 011 ? How can I get 011 as output? The JLS 3.10.1 describes 4 ways to define integers. An integer literal may be expressed in decimal (base 10), hexadecimal (base 16), octal (base 8), or binary (base 2). An octal numeral consists of a digit 0 followed by one or more of the digits 0 through 7 ... A decimal numeral is either the single digit 0, representing the integer zero, or consists of an digit from 1 to 9 optionally followed by one or more digits from 0 to 9 ..

negative zero in python

别来无恙 提交于 2019-11-26 20:59:45
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 don't care that they presumably have different internal representation; I only care about their behavior in a program.) Is there any hidden traps I should be aware of? Check out : −0 (number) in Wikipedia Basically IEEE does actually define a negative zero And by this definition for all purposes : -0.0 == +0.0 == 0 I agree with aaronasterling that -0

Why do floating-point numbers have signed zeros?

你。 提交于 2019-11-26 19:16:59
问题 Why do doubles have -0 as well as +0 ? What is the background and significance? 回答1: -0 is (generally) treated as 0 *******. It can result when a negative floating-point number is so close to zero that it can be considered 0 (to be clear, I'm referring to arithmetic underflow, and the results of the following computations are interpreted as being exactly ±0 , not just really small numbers). e.g. System.out.println(-1 / Float.POSITIVE_INFINITY); -0.0 If we consider the same case with a

h:inputText which is bound to Integer property is submitting value 0 instead of null

守給你的承諾、 提交于 2019-11-26 16:39:14
We are using a h:inputText in a JSF page which is bound to an Integer property (and thus can accept null ). When there is no value written in the h:inputText , the form is submitting a 0 instead of null . We are using Trinidad 1.2.2 and Tomcat 6.0.20 (we also tried with Tomcat 6.0.14 as we read that this could happen with certains Tomcat versions). How is this caused and how can I solve it? BalusC This "feature" was result of a bugfix in EL which was introduced as per Tomcat 6.0.16. As per chapter 1.18.3 of the EL specification , a value of number type which is null should be coerced to 0.

How to add a trailing zero to a price with jQuery

馋奶兔 提交于 2019-11-26 14:26:07
问题 So I have a script which returns a price for a product. However the price may or may not include trailing zeros so sometimes I might have: 258.22 and other times I might have 258.2 In the later case I need to add the trailing zero with jQuery. How would I go about doing this? 回答1: You can use javascript's toFixed method (source), you don't need jQuery. Example: var number = 258.2; var rounded = number.toFixed(2); // rounded = 258.20 Edit: Electric Toolbox link has succumbed to linkrot and

Removing Trailing Zeros in Python [duplicate]

和自甴很熟 提交于 2019-11-26 13:47:10
问题 This question already has answers here : Formatting floats in Python without trailing zeros (15 answers) Closed 5 years ago . 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 is 0 or 00. Any ideas? Thanks! 回答1: Updated Generalized to maintain precision and handle unseen values: import decimal import random def format

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

帅比萌擦擦* 提交于 2019-11-26 12:54:17
问题 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 is: public static bool nz(object obj) { var parsedInt = 0; var parsed = int.TryParse(obj.ToString(), out parsedInt); return IsNull(obj) || (parsed && parsedInt == 0); } Is there a better way? 回答1: I like if ((item.Rate ?? 0) == 0) { } Update 1:

How to make number input area initially empty instead of 0 or 0.00?

馋奶兔 提交于 2019-11-26 12:30:48
I have an input place that should get a number. I want it to be displayed as empty. However when I run my program, I get 0 or 0.00 as default. How can I make it empty? BalusC This will happen if you bound the value to a primitive instead of its wrapper representation. The primitive int always defaults to 0 and the primitive double always defaults to 0.0 . You want to use Integer or Double (or BigDecimal ) instead. E.g.: public class Bean { private Integer number; // ... } Then there are two more things to take into account when processing the form submit. First, you need to instruct JSF to

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

寵の児 提交于 2019-11-26 11:43:19
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 since it's just nothing. If you're imprecise on nothing, it's not nothing anymore. But I don't know much about this topic so it's not for me to say. double x = 0.0; return (x == 0.0) ? true : false; Will that always return true? It is safe to expect that the comparison will return true if and only if the double variable has a value of exactly 0.0 (which