zero

How to parse signed zero?

谁都会走 提交于 2019-12-03 23:25:49
问题 Is it possible to parse signed zero? I tried several approaches but no one gives the proper result: float test1 = Convert.ToSingle("-0.0"); float test2 = float.Parse("-0.0"); float test3; float.TryParse("-0.0", out test3); If I use the value directly initialized it is just fine: float test4 = -0.0f; So the problem seems to be in the parsing procedures of c#. I hope somebody could tell if there is some option or workaround for that. The difference could only be seen by converting to binary:

Why initialize HashSet<>(0) to zero?

≯℡__Kan透↙ 提交于 2019-12-03 16:23:26
问题 I love a HashSet<>() and use this eagerly while initializing this with the default constructor: Set<Users> users = new HashSet<>(); Now, my automatic bean creator (JBoss tools) initializes this as: Set<Users> users = new HashSet<>(0); Why the zero ? The API tells me that this is the initial capacity , but what is the advantage of putting this to zero? Is this advised? 回答1: The default initial capacity is 16, so by passing in 0 you may save a few bytes of memory if you end up not putting

Changing a SUM returned NULL to zero

北战南征 提交于 2019-12-03 10:39:08
问题 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 = @SiteName AND i.[month] = DATEADD(mm, DATEDIFF(mm, 0, GetDate()) -1,0) GROUP BY s.Sites ) AS LoggedIncidents 'tbl_Sites contains a list of reported on sites. 'tbl_Incidents contains a generated list of total incidents by site/date (monthly) 'If a site doesn't have any incidents that

Mysql AVG to ignore zero

此生再无相见时 提交于 2019-12-03 06:44:08
问题 I need to perform an avg on a column, but I know that most of the values in that column will be zero. Out of all possible rows, only two will probably have positive values. How can I tell mySQL to ignore the zeros and only average the actual values? 回答1: Assuming that you might want to not totally exclude such rows (perhaps they have values in other columns you want to aggregate) SELECT AVG(NULLIF(field ,0)) from table 回答2: You could probably control that via the WHERE clause: select avg(

What would you use to zero pad a number in Flex/AS3?

冷暖自知 提交于 2019-12-03 06:11:35
Duplicate of this one. What would you use to pad zeroes to the left of a number in Flex/AS3? Is there an equivalent to printf or NumberFormat that does this? I'm looking for the nicest implementation of this or something similar: public function zeroPad(number:int, width:int):String { // number = 46, width = 4 would return "0046" } public function zeroPad(number:int, width:int):String { var ret:String = ""+number; while( ret.length < width ) ret="0" + ret; return ret; } Performance-wise, I prefer using a String constant and substr, like this: package { public class Helper { private static

Why initialize HashSet<>(0) to zero?

独自空忆成欢 提交于 2019-12-03 04:50:34
I love a HashSet<>() and use this eagerly while initializing this with the default constructor: Set<Users> users = new HashSet<>(); Now, my automatic bean creator (JBoss tools) initializes this as: Set<Users> users = new HashSet<>(0); Why the zero ? The API tells me that this is the initial capacity , but what is the advantage of putting this to zero? Is this advised? The default initial capacity is 16 , so by passing in 0 you may save a few bytes of memory if you end up not putting anything in the set. Other than that there is no real advantage; when you pass 0 the set is created with a

Oracle, adding leading zeros to string (not number)

人盡茶涼 提交于 2019-12-03 04:45:21
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 '1234' to be '0000001234' How can this be done? Whats the best way? Thanks in advance . You can use the LPAD function for that, passing in the string, the length you want it to be, and the character to pad it with. For 10 digits with leading zeroes this would be: LPAD('12H89', 10, '0') The return value is the padded string. See: http://www

Is it possible to differentiate between 0 and -0?

匆匆过客 提交于 2019-12-03 03:23:18
问题 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 = -0; int additinon = 5; num += (IsNegative(num)) ? -addition : addition; Is the value -0 saved in the memory the exact same way as 0 ? 回答1: It depends on the machine you're targeting. On a machine that uses a 2's complement representation for integers

Changing a SUM returned NULL to zero

折月煮酒 提交于 2019-12-03 01:12:06
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 = @SiteName AND i.[month] = DATEADD(mm, DATEDIFF(mm, 0, GetDate()) -1,0) GROUP BY s.Sites ) AS LoggedIncidents 'tbl_Sites contains a list of reported on sites. 'tbl_Incidents contains a generated list of total incidents by site/date (monthly) 'If a site doesn't have any incidents that month it wont be listed. The problem I'm having is that a site doesn't have any Incidents this month

Check if bash variable equals 0 [duplicate]

孤街醉人 提交于 2019-12-03 00:55:53
问题 This question already has answers here : Comparing numbers in Bash (8 answers) Closed last year . 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 operator expected (might be a bit inaccurate due to translation) Please, how can I modify my script to get it working? 回答1: Looks like your depth variable is