numbers

Display SQL query results in php

房东的猫 提交于 2019-11-29 06:56:57
I'm tring to diplay results in php from sql database MySQL statement is correct and does what i want in phpMyAdmin but for some reason my code breaks in the webpage here is the code require_once('db.php'); $sql="SELECT * FROM modul1open WHERE idM1O>=(SELECT FLOOR( MAX( idM1O ) * RAND( ) ) FROM modul1open) ORDER BY idM1O LIMIT 1" $result = mysql_query($sql); echo [$result]; and here is what i get In general I need random number limited from min to max by the table id You need to fetch the data from each row of the resultset obtained from the query. You can use mysql_fetch_array() for this. //

Accept only numbers and a dot in Java TextField

六眼飞鱼酱① 提交于 2019-11-29 06:53:24
I've got one textField where I only accept numbers from the keyboard, but now I have to change it as it's a "price textField" and I would also need to accept a dot "." for any kind of prices. How can I change this in order to get what I need? ptoMinimoField = new JTextField(); ptoMinimoField.setBounds(348, 177, 167, 20); contentPanel.add(ptoMinimoField); ptoMinimoField.setColumns(10); ptoMinimoField.addKeyListener(new KeyAdapter() { public void keyTyped(KeyEvent e) { char caracter = e.getKeyChar(); if (((caracter < '0') || (caracter > '9')) && (caracter != '\b')) { e.consume(); } } }); Suresh

Java library to check whether a String contains a number *without* exceptions

走远了吗. 提交于 2019-11-29 06:48:54
I'm looking for a method that returns a boolean if the String it is passed is a valid number (e.g. "123.55e-9", "-333,556"). I don't want to just do: public boolean isANumber(String s) { try { BigDecimal a = new BigDecimal(s); return true; } catch (NumberFormatException e) { return false; } } Clearly, the function should use a state machine (DFA) to parse the string to make sure invalid examples don't fool it (e.g. "-21,22.22.2", "33-2"). Do you know if any such library exists? I don't really want to write it myself as it's such an obvious problem that I'm sure I'd be re-inventing the wheel.

Algorithm for finding smallest number with given number of factors

谁说胖子不能爱 提交于 2019-11-29 06:48:27
问题 What's the most efficient algorithm anyone can think of that, given a natural number n , returns the least natural number x with n positive divisors (including 1 and x )? For example, given 4 the algorithm should result in 6 (divisors: 1,2,3,6); i.e. 6 is the smallest number having 4 distinct factors. Similarly, given 6, the algorithm should result in 12 (divisors: 1,2,3,4,6,12); i.e. 12 is the smallest number having 6 distinct factors In terms of real-world performance, I'm looking for a

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

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-29 06:35:57
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? 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. I can only think of one: when checking for truth. Strings that are equivalent to 0 , but that are not "0" , such as "0.0" , "0 but true" , "0e0" , etc. all pass looks_like_number and evaluate to 0 in

How to Generate Unique Number of 8 digits?

梦想与她 提交于 2019-11-29 06:17:38
问题 I am using this code to generate a 8 digit unique number. byte[] buffer = Guid.NewGuid().ToByteArray(); return BitConverter.ToUInt32(buffer, 8).ToString(); Does this code really generate a unique number or might it repeat the same number again? 回答1: A GUID is not just a random number; it's composed of segments. Some of the segments will not change at all if the guid is generated on the same computer. By using only 64-bits of the original 128-bits you are breaking the structure of the guid and

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

孤者浪人 提交于 2019-11-29 06:03:28
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<shouldBeFalse.length;i++) if(isNumber(shouldBeFalse[i]) != false) alert("x"); for(i=0;i<alsoTheseBeFalse

c++ pow(2,1000) is normaly to big for double, but it's working. why?

心已入冬 提交于 2019-11-29 05:40:37
the code: #iclude <math.h> int main(){ double somenumber = pow(2, 1000); printf("%lf\n", somenumber); return 0; } i get this huge number: 10715086071862673209484250490600018105614048117055336074437503883703510511249361224931983788156958581275946729175531468251871452856923140435984577574698574803934567774824230985421074605062371141877954182153046474983581941267398767559165543946077062914571196477686542167660429831652624386837205668069376 This is obviously to big for double. How it's working? This is obviously to big for double. How it's working? 2 1000 is within the range of numbers that can be

Default php function that turns negative numbers in 0

假如想象 提交于 2019-11-29 04:30:01
问题 Is there such a thing? for eg $var = -5; echo thefunction($var); // should be 0 $var = 5; echo thefunction($var); // should be 5 回答1: Try max($var,0) , which will have the desired effect. See the manual page for more information. 回答2: Not built-in but, here you have: function thefunction($var){ return ($var < 0 ? 0 : $var); } Hope this helps 回答3: In PHP, checking if a integer is negative and if it is then setting it to zero is easy, but I was looking for something shorter (and potentially

Why don't numbers support .dup?

╄→гoц情女王★ 提交于 2019-11-29 04:26:37
>> a = 5 => 5 >> b = "hello, world!" => "hello, world!" >> b.dup => "hello, world!" >> a.dup TypeError: can't dup Fixnum from (irb):4:in `dup' from (irb):4 I understand that Ruby will make a copy every time you assign an integer to a new variable, but why does Numeric#dup raise an error? Wouldn't this break abstraction, since all objects should be expected to respond to .dup properly? Rewriting the dup method will fix the problem, as far as I can tell: >> class Numeric >> def dup() >> self >> end >> end Does this have a downside I'm not seeing? Why isn't this built into Ruby? Most objects in