numbers

What's a C# regular expression that'll validate currency, float or integer?

元气小坏坏 提交于 2019-11-28 00:01:27
What is a regular expression suitable for C# that'll validate a number if it matches the following? $1,000,000.150 $10000000.199 $10000 1,000,000.150 100000.123 10000 Or the negative equivalents? You can use csmba's regex if you make one slight modification to it. ^\$?(\d{1,3},?(\d{3},?)*\d{3}(.\d{0,3})?|\d{1,3}(.\d{2})?)$ I think ssg is right. It's not a really good use of Regex, especially if your software has to deal with non-US centric data entry. For instance, if the currency symbol is the Euro, or the Japanese Yen or the British Pound any of the other dozen currency symbols out there?

How can I handle numbers bigger than 17-digits in Firefox/IE7?

萝らか妹 提交于 2019-11-27 23:55:36
For a web application I want to be able to handle numbers up to 64 bits in size. During testing, I found that javascript (or the browser as a whole) seems to handle as much as 17 digits. A 64-bit number has a maximum of 20 digits, but after the javascript has handled the number, the least significant 3 digits are rounded and set to 0.... Any ideas where this comes from? More importantly, any idea how to work around it? In Javascript, all numbers are IEEE double precision floating point numbers, which means that you only have about 16 digits of precision; the remainder of the 64 bits are

When does the difference between a string and a number matter in Perl 5?

♀尐吖头ヾ 提交于 2019-11-27 23:54:38
问题 If a string in Perl 5 passes looks_like_number, it might as well be a number. For instance, my $s = "10" + 5; results in $s being assigned 15 . Are there any cases where a string does not behave like its numeric equivalent would? 回答1: When dealing with bitwise operators. 123 ^ 456 is 435, but "123" ^ "456" is "\x05\x07\x05" . The bitwise operators work numerically if either operand is a number. 回答2: I can only think of one: when checking for truth. Strings that are equivalent to 0 , but that

“+” operator for Java-classes

巧了我就是萌 提交于 2019-11-27 23:48:09
问题 I have a class like this: private static class Num { private int val; public Num(int val) { this.val = val; } } Is it possible to add to objects of the class by using the "+"-operator? Num a = new Num(18); Num b = new Num(26); Num c = a + b; 回答1: No, you can't. + is overloaded only for numbers, chars and String , and you are not allowed to define any additional overloadings. There is one special case, when you can concatenate any objects' string representation - if there is a String object in

How to check if a JavaScript number is a real, valid number?

送分小仙女□ 提交于 2019-11-27 23:42:04
问题 MY code is: function isNumber(n){ return typeof n == 'number' && !isNaN(n); } window.onload=function(){ var a=0,b=1,c=2.2,d=-3,e=-4.4,f=10/3; var shouldBeTrue=[a,b,c,d,e,f]; var aa="0",bb="1",cc="2.2",dd="-3",ee="-4.4",ff="10/3"; var shouldBeFalse=[aa,bb,cc,dd,ee,ff]; var aaa,bbb=true,ccc=false,ddd=document.getElementsByTagName('html'); var alsoTheseBeFalse=[aaa,bbb,ccc,ddd,""," ",,null,NaN]; for(var i=0;i<shouldBeTrue.length;i++) if(isNumber(shouldBeTrue[i]) != true) alert("x"); for(i=0;i

range and xrange for 13-digit numbers in Python?

淺唱寂寞╮ 提交于 2019-11-27 23:38:54
range() and xrange() work for 10-digit-numbers. But how about 13-digit-numbers? I didn't find anything in the forum. You could try this. Same semantics as range: import operator def lrange(num1, num2 = None, step = 1): op = operator.__lt__ if num2 is None: num1, num2 = 0, num1 if num2 < num1: if step > 0: num1 = num2 op = operator.__gt__ elif step < 0: num1 = num2 while op(num1, num2): yield num1 num1 += step >>> list(lrange(138264128374162347812634134, 138264128374162347812634140)) [138264128374162347812634134L, 138264128374162347812634135L, 138264128374162347812634136L,

Confusion between isNaN and Number.isNaN in javascript

痞子三分冷 提交于 2019-11-27 23:04:39
I have a confusion in how NaN works. I have executed isNaN(undefined) it returned true . But if I will use Number.isNaN(undefined) it is returning false . So which one i should use. Also why there is so discrepancy in the result. To quote from a ponyfoo article on numbers in ES6 : Number.isNaN is almost identical to ES5 global isNaN method. Number.isNaN returns whether the provided value equals NaN. This is a very different question from “is this not a number?”. So isNaN just checks whether the passed value is not a number or cannot be converted into a Number. Number.isNaN on the other hand

Sorting a List of Strings numerically (1,2,…,9,10 instead of 1,10,2)

被刻印的时光 ゝ 提交于 2019-11-27 22:53:25
I have a List like this: var l = new List<string> {"bla 1.txt","bla 2.txt","bla 10.txt","bla 3.txt"}; If i call l.Sort(), the list gets sorted in the order 1,10,2,3 which makes sense from a pure string point of view, but sucks from a User Perspective. Since I don't want to/can't force my users to name them 01, 02, 03,... I wonder if there is either a built-in method or simple algorithm to detect and sort numbers properly, so that I have 1,2,3,10? Since the numbers are only 1 or 2 characters long (i.e., no more than 99) I could possibly do a regex that temporarily prefixes all 1-digit numbers

Save an integer in two digit format in a variable in Java

删除回忆录丶 提交于 2019-11-27 22:46:11
How can I store an integer in two digit format in Java? Like can I set int a=01; and print it as 01 ? Also, not only printing, if I say int b=a; , b should also print its value as 01 . I think this is what you're looking for: int a = 1; DecimalFormat formatter = new DecimalFormat("00"); String aFormatted = formatter.format(a); System.out.println(aFormatted); Or, more briefly: int a = 1; System.out.println(new DecimalFormat("00").format(a)); An int just stores a quantity, and 01 and 1 represent the same quantity so they're stored the same way. DecimalFormat builds a String that represents the

is it ok to specialize std::numeric_limits<T> for user-defined number-like classes?

ぃ、小莉子 提交于 2019-11-27 22:45:04
The documentation of std::numeric_limits<T> says it should not be specialized for non-fundamental types. What about number-like user-defined types? If I define my own type T which represents a numeric value and overloads numeric operators, and for which the information represented by numeric_limits makes sense -- will anything break if I specialize numeric_limits for that type? Short answer: Go ahead, nothing bad will happen. Long answer: The C++ standard extensively protects the ::std namespace in C++11 17.6.4.2.1, but specifically allows your case in paragraphs 1 and 2: The behavior of a C++