numbers

R ifelse avoiding change in date format [duplicate]

半腔热情 提交于 2019-11-28 02:05:46
This question already has an answer here: How to prevent ifelse() from turning Date objects into numeric objects 6 answers I am trying to make ifesle for two dates. I have two columns- DateIn and DateOut. I need to add 3rd variable, which would show "DateOut" if there is date value, or DateIn if there is : DateIn DateOut Travel date 2010-11-24 <NA> 2010-11-24 2011-12-21 2012-01-21 2012-01-21 2010-10-25 2010-11-25 2010-11-25 2014-01-14 <NA> 2014-01-14 I tried to do that with TravelDate <- ifelse(is.na(DateIn), DateOut, DateIn) But the result I am gettin is: DateIn DateOut Travel date 2010-11-24

Float numbers in Java

若如初见. 提交于 2019-11-28 02:01:17
Could anyone please me why the output of the following programme is not " different different"? public static void main(String[] args) { float f1=3.2f; float f2=6.5f; if(f1==3.2) System.out.println("same"); else System.out.println("different"); if(f2==6.5) System.out.println("same"); else System.out.println("different"); } o/p :different same 6.5 has a finite binary representation: 110.1 Any floating type with at least 4 significant bits can represent this number perfectly. 110.100000000000000000000 (float) = 6.5 110.10000000000000000000000000000000000000000000000000 (double) = 6.5 3.2 on the

Allow only numbers into a input text box

為{幸葍}努か 提交于 2019-11-28 01:59:38
问题 I have a number input text box and I want to allow the user to edit but do not want to allow the user to enter any other text except numbers. I want them only to be able to use the arrows on the number input box. <input type = "number" min="0" max="10" step="0.5" input id="rating" name = "rating" class = "login-input" placeholder = "Rating 1-5:" value="0"> 回答1: You can achieve this by pure JavaScript . Create this function that you can reuse in your script. function allowNumbersOnly(e) { var

how to loop from 0000 to 9999 and convert the number to the relative string?

↘锁芯ラ 提交于 2019-11-28 01:21:46
问题 i want to get some string, range from 0000 to 9999, that's to say, i want to print the following string: 0000 0001 0002 0003 0004 0005 0006 .... 9999 i tried to use print "\n".join([str(num) for num in range(0, 9999)]) , but failed, i get the following number: 0 1 2 3 4 5 6 ... 9999 i want python to add the prefix 0 automatically, making the number remain 4 bit digits all the time. can anyone give a hand to me? any help appreciated. 回答1: One way to get what you want is to use string

How to get numbers out of string?

怎甘沉沦 提交于 2019-11-28 01:18:54
问题 I'm using a Java StreamTokenizer to extract the various words and numbers of a String but have run into a problem where numbers which include commas are concerned, e.g. 10,567 is being read as 10.0 and ,567. I also need to remove all non-numeric characters from numbers where they might occur, e.g. $678.00 should be 678.00 or -87 should be 87. I believe these can be achieved via the whiteSpace and wordChars methods but does anyone have any idea how to do it? The basic streamTokenizer code at

Accept only numbers and a dot in Java TextField

蓝咒 提交于 2019-11-28 00:24:51
问题 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

java.lang.Number doesn't implement “+” or any other operators?

99封情书 提交于 2019-11-28 00:12:33
问题 I'm creating a class which is supposed to be able to be used with an array of any type of number (float, int, etc), so here is one method I have: // T extends Number public synchronized T[] average() { Number[] ret = new Number[queue[0].length]; for (int i = 0; i < ret.length; ++i) { for (int j = 0; j < size; ++j) { ret[i] += queue[j][i]; // WTF ERROR?! } ret[i] /= size; // WTF ERROR?! } return (T[])ret; } Except this won't compile because "Number" doesn't implement the "+=" or "/=" operators

Parse currency into numbers in Python

别来无恙 提交于 2019-11-28 00:07:40
I just learnt from Format numbers as currency in Python that the Python module babel provides babel.numbers.format_currency to format numbers as currency. For instance, from babel.numbers import format_currency s = format_currency(123456.789, 'USD', locale='en_US') # u'$123,456.79' s = format_currency(123456.789, 'EUR', locale='fr_FR') # u'123\xa0456,79\xa0\u20ac' How about the reverse, from currency to numbers, such as $123,456,789.00 --> 123456789 ? babel provides babel.numbers.parse_number to parse local numbers, but I didn't found something like parse_currency . So, what is the ideal way

PHP subtract array values

╄→尐↘猪︶ㄣ 提交于 2019-11-28 00:07:00
I have an array with keys and values. Each value is an integer. I have an other array with the same keys. How can I subtract all of the values for the matching keys? Also there might be keys that do not occur in the second array but both arrays have the same length. If there is a key in array 2 that is not present in array 1 its value should be unchanged. If there is a key in the first array that is not in the second it should be thrown away. How do I do it? Is there any built-in function for this? If I would write a script it would be some kind of for loop like this: $arr1 = array('a' => 1,

JavaScript format number to day with always 3 digits [duplicate]

删除回忆录丶 提交于 2019-11-28 00:02:29
Possible Duplicate: How can I create a Zerofilled value using JavaScript? I have to output a day number that must always have 3 digits. Instead of 3 it must write 003 , instead of 12 it must write 012 . If it is greater than 100 output it without formatting. I wonder if there's a regex that I could use or some quick in-line script, or I must create a function that should do that and return the result. Thanks! How about: zeroFilled = ('000' + x).substr(-3) For arbitrary width: zeroFilled = (new Array(width).join('0') + x).substr(-width) As per comments, this seems more accurate: lpad = function