numbers

JavaScript regular expression to match X digits only

断了今生、忘了曾经 提交于 2019-12-01 15:23:58
Can someone help my pea brain figure out why my simple regular expression is not working as I am expecting/wanting it to. I want to match a date format of MM/DD/YYYY with exactly 2 and 4 digits, so something like 01/16/1955. My code below does that, but it also matches 2+ and 4+ digits, so something like 011/16/1955 or 01/16/19555 (1 extra digit) pass my validation as well. //validate date of birth var dob_label = $date_of_birth.find('label').text().slice(0, -1), dob_mm = $dob_mm.val(), dob_dd = $dob_dd.val(), dob_yyyy = $dob_yyyy.val(), regex_two_digit = /^\d{2}$/, regex_four_digit = /^\d{4}$

Dividing decimals yields invalid results in Python 2.5 to 2.7

大城市里の小女人 提交于 2019-12-01 15:20:33
After a very thorough read of the Python's decimal module documentation , I still find myself puzzled by what happens when I divide a decimal. In Python 2.4.6 (makes sense): >>> import decimal >>> decimal.Decimal(1000) / 10 Decimal("100") In Python 2.5.6, Python 2.6.7, and Python 2.7.2 (puzzling): >>> import decimal >>> decimal.Decimal(1000) / 10 Decimal('0.00000-6930898827444486144') More confusing yet, that result doesn't even appear to be valid: >>> decimal.Decimal('0.00000-6930898827444486144') Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/opt/local/Library

What to do when you need to store a (very) large number?

你说的曾经没有我的故事 提交于 2019-12-01 15:13:49
问题 I am trying to do a Project Euler problem but it involves adding the digits of a very large number. (100!) Using Java int and long are too small. Thanks for any suggestions 回答1: Class BigInteger looks like it might be what you are looking for. 回答2: Use BigInteger. Here is an example from the book Java Examples in a Nutshell that involves computing factorials, with caching. import java.math.BigInteger; import java.util.ArrayList; /* * Copyright (c) 2000 David Flanagan. All rights reserved. *

round number to the first 3 digits (start with digit != 0)

丶灬走出姿态 提交于 2019-12-01 15:00:48
问题 is there a predefined format-function that rounds a number to the first 3 digits? (The start should be a numbers != 0) -0.02528498 to -0.0253 1.857403 to 1.86 2060943 to 2060000 0.00006513832 to 0.0000651 回答1: You can use the function signif : signif(-0.02528498, 3) # [1] -0.0253 signif(1.857403, 3) # [1] 1.86 signif(2060943, 3) # [1] 2060000 signif(0.00006513832, 3) # [1] 0.0000651 来源: https://stackoverflow.com/questions/29674349/round-number-to-the-first-3-digits-start-with-digit-0

Select from a range but exclude certain numbers [duplicate]

六眼飞鱼酱① 提交于 2019-12-01 14:34:12
问题 This question already has answers here : How to get a random number from a range, excluding some values (8 answers) Closed 5 years ago . Is it possible to pick a random number from a given range (1-90), but exclude certain numbers. The excluded numbers are dynamically created but lets say they are 3, 8, and 80. I have managed to create random number generator but couldn't identify any functions that let me fulfill my requirements. Random r = new Random(); this.num = r.Next(1, 90); The numbers

parseInt() parses number literals with exponent incorrectly

僤鯓⒐⒋嵵緔 提交于 2019-12-01 14:18:40
问题 I have just observed that the parseInt function doesn't take care about the decimals in case of integers (numbers containing the e character). Let's take an example: -3.67394039744206e-15 > parseInt(-3.67394039744206e-15) -3 > -3.67394039744206e-15.toFixed(19) -3.6739e-15 > -3.67394039744206e-15.toFixed(2) -0 > Math.round(-3.67394039744206e-15) 0 I expected that the parseInt will also return 0 . What's going on at lower level? Why does parseInt return 3 in this case (some snippets from the

Why is type conversion from u64 to usize allowed using `as` but not `From`?

ε祈祈猫儿з 提交于 2019-12-01 14:07:12
问题 The first conversion using 'as' compiles, but the second one using the 'From' trait does not: fn main() { let a: u64 = 5; let b = a as usize; let b = usize::from(a); } Using Rust 1.34.0, I get the following error: error[E0277]: the trait bound `usize: std::convert::From<u64>` is not satisfied --> src/main.rs:4:13 | 4 | let b = usize::from(a); | ^^^^^^^^^^^ the trait `std::convert::From<u64>` is not implemented for `usize` | = help: the following implementations were found: <usize as std:

Java8两大特性(一)——Stream

风格不统一 提交于 2019-12-01 12:47:37
什么是Stream?   Stream(流)是一个来自数据源的元素队列并且支持聚合操作,元素流在管道中经过中间操作,最终操作得到结果。    数据源 :集合,数组,I/O channel,产生器generator。    聚合操作 :类似于sql比如:filter,find,map,match,sorted. 生成流: stream() − 为集合创建串行流。 parallelStream() − 为集合创建并行流。 通过例子看方法: list.stream().limit(10).sorted().forEach(System.out::println); 上面例子:取前10条》排序》循环输出 List<Integer> numbers = Arrays.asList(3, 2, 2, 3, 7, 3, 5);List<Integer> squaresList = numbers.stream().map( i -> i*i).distinct().collect(Collectors.toList()); 上面例子:将本身映射成本身的平方》去重》转化为list   List<String>strings = Arrays.asList("abc", "", "bc", "efg", "abcd","", "jkl");String mergedString = strings

Display numbers instead of points using pyplot [duplicate]

。_饼干妹妹 提交于 2019-12-01 12:39:27
问题 This question already has answers here : Matplotlib scatter plot with different text at each data point (4 answers) Closed 2 years ago . I have a nx2 dimension array representing n points with their two coordinates x, y. Using pyplot, I would like to display the number n of my points instead of just the points with no way to know which is what. I have found a way to legend my points but really what I would like is only the number. How can I achieve this ? 回答1: You may use plt.text to place

How to make TextBox to receive only number key values using KeyDown Event in C#?

本秂侑毒 提交于 2019-12-01 12:31:28
This code in my form updates the textBox1.Text twice whenever number keys are pressed. private void textBox1_KeyDown( object sender, KeyEventArgs e ) { //MessageBox.Show(); if( char.IsNumber((char)e.KeyCode) ) { textBox1.Text += (char)e.KeyCode; } } Explain why if you can? Modify the code or provide me a better solution for this. Input ( in textbox1 ): 54321 Output: 1234554321 When you press a key, a character is already appended to your TextBox . Then you run the following code and, if the key represents a number, you append it again: if (char.IsNumber((char)e.KeyCode)) { textBox1.Text +=