numbers

How can I check if a char is a letter or a number?

纵然是瞬间 提交于 2019-11-30 03:57:44
问题 I have a string and I want to loop it so that I can check if every char is a letter or number. $s = "rfewr545 345b"; for ($i=1; $i<=strlen($s); $i++){ if ($a[$i-1] == is a letter){ echo $a[$i-1]." is a letter"; } else { echo $a[$i-1]." is a number"; } } How can I check if a char is a letter or a number? 回答1: To test if character is_numeric , use: is_numeric($a[$i-1]) As below: $s = "rfewr545 345b"; for ($i = 0; $i < strlen($s); $i++){ $char = $s[$i]; if (is_numeric($char)) { echo $char . ' is

Concatenating numbers in virtual column expression throws ORA-12899: value too large for column

99封情书 提交于 2019-11-30 03:55:38
问题 While I gave this answer to a question yesterday, I suggested to use a VIRTUAL COLUMN for computed values instead of manually updating it. I did a test myself, and figured out an issue with the data size that the virtual column expression takes while concatenating two NUMBER type columns. Though, no issue while concatenating two characters. DB version : SQL> select banner from v$version where rownum = 1; BANNER --------------------------------------------------------------------------------

Fortran: handling integer values of size: ~700000000000

家住魔仙堡 提交于 2019-11-30 03:54:14
问题 Currently I'm brushing up on my Fortran95 knowledge (don't ask why)... I'm running in to a problem though. How does one handle large integers, eg. the size of: ~700000000000 INTEGER(KIND=3) cannot hold this number. If anyone is interested the compiler I have available is Silverfrost FTN95. I am using the integer to run through a larger set of data. Do you have any suggestions? 回答1: The standard solution (since Fortran 95, so I assume your compiler supports it) is to use the SELECTED_INT_KIND

Output numbers with digit grouping (1000000 as 1,000,000 and so on)

放肆的年华 提交于 2019-11-30 03:51:21
问题 While it is easy to write something that does this by myself, I often wondered if there was something like this in iomanip or somewhere. However, I never found something useful. Ideally, it'd be sensitive to locales (e.g. in Germany you'd write 1,234,567.89 as 1.234.567,89) and hence highly superior to building the comma-string by hand. 回答1: According to this thread, you can set a locale on your output stream by doing something like: #include <iostream> #include <locale> #include <string>

Numbers to Roman Numbers with php

依然范特西╮ 提交于 2019-11-30 03:43:40
I need to transform ordinary numbers to Roman numerals with php and I have this code: <?php function roman2number($roman){ $conv = array( array("letter" => 'I', "number" => 1), array("letter" => 'V', "number" => 5), array("letter" => 'X', "number" => 10), array("letter" => 'L', "number" => 50), array("letter" => 'C', "number" => 100), array("letter" => 'D', "number" => 500), array("letter" => 'M', "number" => 1000), array("letter" => 0, "number" => 0) ); $arabic = 0; $state = 0; $sidx = 0; $len = strlen($roman); while ($len >= 0) { $i = 0; $sidx = $len; while ($conv[$i]['number'] > 0) { if

C++ complex numbers, what is the right format?

落爺英雄遲暮 提交于 2019-11-30 03:35:58
I want to use C++ with complex numbers. Therefore I included #include <complex> . Now my question is: How do I declare a variable?(so what is the format called for let's say: 1 + i ?) Thanks in advance :-) // 1 + 2i std::complex<double> c(1, 2); The constructor of std::complex has two parameters: The first, wich has the real part of the number. The second, wich has the imaginary part of the number. For example: std::complex<float> my_complex(1,1); //1 + 1i Also, C++11 introduces user defined literals , wich allows us to implement (Or be implemented by the standard library, as in this C++14

How to speed up series generation?

纵饮孤独 提交于 2019-11-30 03:25:45
The problem requires to generate the n-th element of a sequence that is similar to Fibonacci sequence. However, it's a bit tricky because n is very large (1 <= n <= 10^9). The answer then modulo 1000000007. The sequence is defined as follows: Using generating function, I obtain the following formula: If I use the sequence approach then the answer can be modulo, but it run extremely slow. In fact, I got time limit exceed many times. I also tried to use a table to pre-generate some initial values (cache), still it was not fast enough. In addition, the maximum number of elements that I can store

Double multiplied by 100 and then cast to long is giving wrong value

拥有回忆 提交于 2019-11-30 03:06:43
I have the following code: Double i=17.31; long j=(long) (i*100); System.out.println(j); O/P : 1730 //Expected:1731 Double i=17.33; long j=(long) (i*100); System.out.println(j); O/P : 1732 //Expected:1733 Double i=17.32; long j=(long) (i*100); System.out.println(j); O/P : 1732 //Expected:1732{As expected} Double i=15.33; long j=(long) (i*100); System.out.println(j); O/P : 1533 //Expected:1533{as Expected} I have tried to Google but unable to find reason.I am sorry if the question is trivial. None of the answers seem to deal with why 17.32 acted different. 1. Why it occurred The difference in

Strange javascript operator: expr >>> 0 [duplicate]

风格不统一 提交于 2019-11-30 03:03:31
This question already has an answer here: What is the JavaScript >>> operator and how do you use it? 7 answers the following function is designed to implement the indexOf property in IE. If you've ever had to do this, I'm sure you've seen it before. if (!Array.prototype.indexOf){ Array.prototype.indexOf = function(elt, from){ var len = this.length >>> 0; var from = Number(arguments[1]) || 0; from = (from < 0) ? Math.ceil(from) : Math.floor(from); if (from < 0) from += len; for (; from < len; from++){ if (from in this && this[from] === elt) return from; } return -1; }; } I'm wondering if it's

Input type “number” won't resize

爱⌒轻易说出口 提交于 2019-11-30 03:02:37
Why won't my input resize when I change the type to type="number" but it works with type="text" ? EXAMPLE Email: <input type="text" name="email" size="10"><br/> number: <input type="number" name="email" size="10"> Seem like the input type number does not support size attribute or it's not compatible along browsers, you can set it through CSS instead: input[type=number]{ width: 80px; } Updated Fiddle Incorrect usage. Input type number it's made to have selectable value via arrows up and down. So basically you are looking for "width" CSS style. Input text historically is formatted with