zero

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

℡╲_俬逩灬. 提交于 2019-11-27 06:31:41
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? eglasius I like if ((item.Rate ?? 0) == 0) { } Update 1: You could also define an extension method like: public static bool IsNullOrValue(this double? value,

Remove/ truncate leading zeros by javascript/jquery

不打扰是莪最后的温柔 提交于 2019-11-27 05:30:46
问题 Suggest solution for removing or truncating leading zeros from number(any string) by javascript,jquery. 回答1: You can use a regular expression that matches zeroes at the beginning of the string: s = s.replace(/^0+/, ''); 回答2: I would use the Number() function: var str = "00001"; str = Number(str).toString(); >> "1" Or I would multiply my string by 1 var str = "00000000002346301625363"; str = (str * 1).toString(); >> "2346301625363" 回答3: Maybe a little late, but I want to add my 2 cents. if

Python Force python to keep leading zeros of int variables

假如想象 提交于 2019-11-27 05:21:25
Below is a section of code which is part of a functional decryption and encryption program. while checkvar < maxvar: # is set to < as maxvar is 1 to high for the index of var #output.append("%02d" % number) i =ord(var[checkvar]) - 64 # Gets postional value of i i = ("%02d" % i) if (checkvar + 1) < maxvar: j =ord(var[(checkvar + 1)]) - 64 # Gets postional value of i j = ("%02d" % j) i = str(i) + str(j) #'Adds' the string i and j to create a new i li.append(int(i)) checkvar = checkvar + 2 print li As you can see the two variables i and j are first treated as string to add a 0 in front of any

Comparing floating point numbers in C

拈花ヽ惹草 提交于 2019-11-27 05:02:14
I've got a double that prints as 0.000000 and I'm trying to compare it to 0.0f , unsuccessfully. Why is there a difference here? What's the most reliable way to determine if your double is zero? To determine whether it's close enough to zero that it will print as 0.000000 to six decimal places, something like: fabs(d) < 0.0000005 Dealing with small inaccuracies in floating-point calculations can get quite complicated in general, though. If you want a better idea what value you've got, try printing with %g instead of %f . You can do a range. Like -0.00001 <= x <= 0.00001 This is fundamental

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

与世无争的帅哥 提交于 2019-11-27 04:32:41
问题 This question already has an answer here: 'property: 0' or 'property: 0px' in CSS? 9 answers 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 with '0' is that if you change it to some non-zero value, you might forget to add the 'px'. And when making a value '0', you may forget to remove the 'px'. I

JAVA How to remove trailing zeros from a double [duplicate]

非 Y 不嫁゛ 提交于 2019-11-27 02:07:08
问题 This question already has an answer here: How to nicely format floating numbers to String without unnecessary decimal 0? 24 answers For example I need 5.0 to become 5 , or 4.3000 to become 4.3 . 回答1: Use DecimalFormat double answer = 5.0; DecimalFormat df = new DecimalFormat("###.#"); System.out.println(df.format(answer)); 回答2: You should use DecimalFormat("0.#") For 4.3000 Double price = 4.3000; DecimalFormat format = new DecimalFormat("0.#"); System.out.println(format.format(price)); output

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

放肆的年华 提交于 2019-11-26 23:34:06
This question already has an answer here: Formatting a number with leading zeros in PHP 14 answers 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 You can use sprintf: http://php.net/manual/en/function.sprintf.php <?php $num = 4; $num_padded = sprintf("%02d", $num); echo $num_padded; // returns 04 ?> It will only add the zero if it's less than the required number of characters. Edit: As pointed out by

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

99封情书 提交于 2019-11-26 22:26:23
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 looking, but I'm not really sure if the browser interprets 0px differently than 0 . Does anyone know which one is better or correct? Unit identifiers are optional , but there is no noted performance increase (although you are saving two characters). CSS2 - From W3C CSS 2.1 Specification for Syntax and basic data types : The format of a length value (denoted

springmvc 零配置文件 记录001 --初始化

与世无争的帅哥 提交于 2019-11-26 22:22:08
最近工作需要用到springmvc4,很久没用spring了变化还是很大,记录下搭建一个基于annotation的零配置文件的spring、springmvc、jpa、bootstrap的简单框架。 开发环境 开发工具:spring sts 3.6.4 jdk:1.7.55 64 bit web server: Pivotal tc Server Developer Edition (Runtime) v3.1 mysql: 5.5.23 maven:3.2.3 springmvc annotation @Configuration : 类似于spring配置文件,负责注册bean,对应的提供了@Bean注解。需要org.springframework.web.context.support.AnnotationConfigWebApplicationContext注册到容器中。 @ComponentScan : 注解类查找规则定义 <context:component-scan/> @EnableAspectJAutoProxy : 激活Aspect自动代理 <aop:aspectj-autoproxy/> @Import @ImportResource: 关联其它spring配置 <import resource="" /> @EnableCaching :启用缓存注解

Distinguish zero and negative zero

流过昼夜 提交于 2019-11-26 22:04:49
问题 I have run into a situation in my code where a function returns a double, and it is possible for this double to be a zero, a negative zero, or another value entirely. I need to distinguish between zero and negative zero, but the default double comparison does not. Due to the format of doubles, C++ does not allow for comparison of doubles using bitwise operators, so I am unsure how to procede. How can I distinguish between the two? 回答1: Call std::signbit() to determine the state of the sign