numbers

How do I format a double to a string and only show decimal digits when necessary?

扶醉桌前 提交于 2019-11-27 22:15:49
问题 I have code like: lblFranshizShowInvwNoskhehEdit.Text = string.Format("{0:n}", (double)(int.Parse(drDarman["FranshizDarsad"].ToString()) * Convert.ToInt64(RadNumerictxtPayInvwNoskhehEdit.Text)) / 100); But {0:n0} string format forces the label's text to not have decimal digits and {0:n} string format forces the label's text to have 2 decimal digits (default). In my scenario I just want decimal digits when necessary / without rounding them / how can I do that? 回答1: You can just do: string

Bash Number Limit?

人走茶凉 提交于 2019-11-27 22:13:16
问题 I asked a question earlier that involved pulling large primes from a text file and putting them into another file. It was supposed to grab every prime up to and including the first prime after 2^32, and for some reason this script stopped working. #!/bin/bash n=4294967296 last=0 while read number do if [ $last -gt $n ] then break fi echo $number last=$number done < primes.txt > primes2.txt It ended up looping through these 11 numbers: 4232004449 4232004479 4232004493 4232004509 4232004527

Does Java have mutable types for Integer, Float, Double, Long?

不打扰是莪最后的温柔 提交于 2019-11-27 21:45:48
I am in a situation where I want to use mutable versions of things like Integer. Do I have to use these classes (below) or does Java have something built in? http://www.java2s.com/Code/Java/Data-Type/Amutableintwrapper.htm Bozho No, Java doesn't have these built in. And that is for a reason. Using mutable types is dangerous, as they can easily be misused. Additionally, it is really easy to implement it. For example, commons-lang has a MutableInt . You could always wrap the value in an array like int[] mutable = {1}; if including the code for a mutable wrapper class is too cumbersome. Since JDK

Generate N random numbers whose sum is a constant K - Excel

冷暖自知 提交于 2019-11-27 21:26:01
How can I generate those numbers in Excel. I have to generate 8 random numbers whose sum is always 320. I need around 100 sets or so. http://en.wikipedia.org/wiki/User:Skinnerd/Simplex_Point_Picking . Two methods are explained here. Or any other way so I can do it in Excel. Razvan You could use the RAND() function to generate N numbers (8 in your case) in column A. Then, in column B you could use the following formula B1=A1/SUM(A:A)*320 , B2=A2/SUM(A:A)*320 and so on (where 320 is the sum that you are interested into). So you can just enter =RAND() in A1, then drag it down to A8. Then enter

Using inherited overloaded methods

ぃ、小莉子 提交于 2019-11-27 21:11:09
问题 I have two classes: public class ClassA { public void method(Number n) { System.out.println("ClassA: " + n + " " + n.getClass()); } } and: public class ClassB extends ClassA { public void method(Integer d) { System.out.println("ClassB: " + d + " " + d.getClass()); } } But when I run: ClassA a = new ClassB(); a.method(3); I get: ClassA: 3 class java.lang.Integer My question is, why isn't ClassB 's method being used? a is an instance of ClassB , and ClassB 's method() has an Integer parameter..

Convert A to 1 B to 2 … Z to 26 and then AA to 27 AB to 28 (column indexes to column references in Excel)

旧巷老猫 提交于 2019-11-27 20:37:45
Does any one have algorithm or logic to Convert A to 1 ,B to 2, ... ,Z to 26 and then ,AA to 27, AB to 28 etc. In other words, converting a column index into the column reference in Excel. Have a look at these /// <summary> /// 1 -> A<br/> /// 2 -> B<br/> /// 3 -> C<br/> /// ... /// </summary> /// <param name="column"></param> /// <returns></returns> public static string ExcelColumnFromNumber(int column) { string columnString = ""; decimal columnNumber = column; while (columnNumber > 0) { decimal currentLetterNumber = (columnNumber - 1) % 26; char currentLetter = (char)(currentLetterNumber +

Format a number with leading sign

别来无恙 提交于 2019-11-27 20:22:35
How do I format in Java a number with its leading sign? Negative numbers are correctly displayed with leading - , but obviously positive numbers are not displayed with + . How to do that in Java? My current currency format string is \#\#\#,\#\#\#,\#\#\#,\#\#\#,\#\#0.00 (yes, I need to format positive/negative currency values) Use a negative subpattern, as described in the javadoc for DecimalFormat . DecimalFormat fmt = new DecimalFormat("+#,##0.00;-#"); System.out.println(fmt.format(98787654.897)); System.out.println(fmt.format(-98787654.897)); produces (in my French locale where space is the

Adding space between numbers?

核能气质少年 提交于 2019-11-27 20:03:25
I'm trying to make a number input. I've made so my textbox only accepts numbers via this code: function isNumber(evt) { evt = (evt) ? evt : window.event; var charCode = (evt.which) ? evt.which : evt.keyCode; if (charCode > 31 && (charCode < 48 || charCode > 57)) { return false; } return true; } But now the question comes to, how would I create spaces as the user is typing in their number, much like the iPhone's telephone spacing thing, but with numbers so for example if they type in: 1000 it will become 1 000; 1 10 100 1 000 10 000 100 000 1 000 000 10 000 000 100 000 000 1 000 000 000 Etc...

How can I generate a random number in a certain range?

有些话、适合烂在心里 提交于 2019-11-27 19:59:39
How can I create an app that generates a random number in Android using Eclipse and then show the result in a TextView field? The random number has to be in a range selected by the user. So, the user will input the max and min of the range, and then I will output the answer. Fantômas To extend what Rahul Gupta said: You can use the Java function int random = Random.nextInt(n) . This returns a random int in the range [0, n-1] . I.e., to get the range [20, 80] use: final int random = new Random().nextInt(61) + 20; // [0, 60] + 20 => [20, 80] To generalize more: final int min = 20; final int max

How to convert strings numbers to integers in a list?

佐手、 提交于 2019-11-27 19:52:47
I have a list say: ['batting average', '306', 'ERA', '1710'] How can I convert the intended numbers without touching the strings? Thank you for the help. Alex Martelli changed_list = [int(f) if f.isdigit() else f for f in original_list] The data looks like you would know in which positions the numbers are supposed to be. In this case it's probably better to explicitly convert the data at these positions instead of just converting anything that looks like a number: ls = ['batting average', '306', 'ERA', '1710'] ls[1] = int(ls[1]) ls[3] = int(ls[3]) S.Lott Try this: def convert( someList ): for