numbers

Convert scientific notation to decimal notation

帅比萌擦擦* 提交于 2019-12-01 20:43:10
There is a similar question on SO which suggests using NumberFormat which is what I have done. I am using the parse() method of NumberFormat. public static void main(String[] args) throws ParseException{ DecToTime dtt = new DecToTime(); dtt.decToTime("1.930000000000E+02"); } public void decToTime(String angle) throws ParseException{ DecimalFormat dform = new DecimalFormat(); //ParsePosition pp = new ParsePosition(13); Number angleAsNumber = dform.parse(angle); System.out.println(angleAsNumber); } The result I get is 1.93 I didn't really expect this to work because 1.930000000000E+02 is a

How to avoid the L in Python

回眸只為那壹抹淺笑 提交于 2019-12-01 20:41:54
>>> sum(range(49999951,50000000)) 2449998775L Is there any possible way to avoid the L at the end of number? Inbar Rose The L is just for you. (So you know its a long ) And it is nothing to worry about. >>> a = sum(range(49999951,50000000)) >>> a 2449998775L >>> print a 2449998775 As you can see, the printed value (actual value) does not have the L it is only the repr (representation) that displays the L Consult this post You are looking at a Python literal representation of the number, which just indicates that it is a python long integer. This is normal . You do not need to worry about that

random number guessing game

♀尐吖头ヾ 提交于 2019-12-01 20:33:05
I am making a random number guessing game which the computer thinks of a number between 1-100. It then asks you what it is and tells you if you are right or wrong. However, whenever I debug, it says that it is higher or lower than the actual random number for some reason. Plus, it says two of those statements at once. Also, I'm not sure how to say how many guesses the person has taken. Here is my unsuccessful code. static void Main(string[] args) { Random random = new Random(); int returnValue = random.Next(1, 100); int Guess = 0; Console.WriteLine("I am thinking of a number between 1-100. Can

Convert Hexadecimal to String

房东的猫 提交于 2019-12-01 19:35:51
问题 To convert String to Hexadecimal i am using: public String toHex(String arg) { return String.format("%040x", new BigInteger(1, arg.getBytes("UTF-8"))); } This is outlined in the top-voted answer here: Converting A String To Hexadecimal In Java How do i do the reverse i.e Hexadecimal to String? 回答1: You can reconstruct bytes[] from the converted string, here's one way to do it: public String fromHex(String hex) throws UnsupportedEncodingException { hex = hex.replaceAll("^(00)+", ""); byte[]

How to limit the textarea to only hold numbers?

拥有回忆 提交于 2019-12-01 19:30:27
I'm trying to make a date textbox on my blog, and the date is only numbers. I don't want anybody making a mistake typing a letter. Is there any way to limit the characters to only numerals? Thanks! Madhawa Priyashantha If you use jQuery, you can do it like in this jsfiddle $('input').keypress(function(e) { var a = []; var k = e.which; for (i = 48; i < 58; i++) a.push(i); if (!(a.indexOf(k)>=0)) e.preventDefault(); }); Use HTML5 input number type instead and leverage native browser validation. Thus, no JavaScript required. <input type="number" /> It has wide support in browsers and it's the

How to check if float is a whole number?

醉酒当歌 提交于 2019-12-01 19:26:11
问题 There is some kind of function for the printf function in which you can use %g, which will show the whole number 3 if the float is 3.00 and will show 3.01 if it's actually a float, is there any way you can do this through some code? 回答1: There isn't really a simple answer Integral values do have exact representations in the float and double formats. So, if it's really already integral, you can use: f == floor(f) However, if your value is the result of a calculation which at one point involved

How to insert spaces in a big number to make it more readable?

此生再无相见时 提交于 2019-12-01 19:18:45
I came up with this, since other examples provided on stackoverflow were in C# string number_fmt(ulong n) { // cout << "(" << n << ")" << endl; char s[128]; sprintf(s, "%lu", n); string r(s); reverse(r.begin(), r.end()); int space_inserted = 0; size_t how_many_spaces = r.length() / 3; if(r.length() % 3 != 0) how_many_spaces += 1; for(int i = 1; i < how_many_spaces; ++i) { r.insert(3 * i + space_inserted, " "); space_inserted += 1; } reverse(r.begin(), r.end()); return r; } Do you know any better solution ? This one is different, but better is subjective. I think it's very succinct and clear

“e” in a bunch of numbers [duplicate]

╄→гoц情女王★ 提交于 2019-12-01 19:11:34
Possible Duplicate: What number is e+000 Found 2.4397e6 in Enum tutorial Result from printing that: 2439700.0 , what does the e mean? I don't think it's primitive data type though. It's the exponent in scientific notation - so that value is 2.4397 x 10 6 . See the JLS section 3.10.2 for precise details on floating point literals. "e" is a exponent in scientific notation . 来源: https://stackoverflow.com/questions/13759415/e-in-a-bunch-of-numbers

Spreadsheets: how do I SUM values in a column, only if the text column has a 1?

。_饼干妹妹 提交于 2019-12-01 18:43:58
Let's say I have this data 4 1 4 0 4 1 3 0 5 1 How do I write a function (using SUM or something like that) to add all the values on the left, if the values on the right are 1, or true The total should be 13 Assuming columns A and B are used... Check just for 1: =SUMIF(B1:B5,"=1",A1:A5) If you want to check for TRUE also: =SUMIF(B1:B5,"=1",A1:A5) + SUMIF(B1:B5,"=TRUE",A1:A5) sort by column b, then auto-sum the values you want in column a. cheap & lazy solution. 来源: https://stackoverflow.com/questions/3832457/spreadsheets-how-do-i-sum-values-in-a-column-only-if-the-text-column-has-a-1

How to check if float is a whole number?

旧城冷巷雨未停 提交于 2019-12-01 17:45:37
There is some kind of function for the printf function in which you can use %g, which will show the whole number 3 if the float is 3.00 and will show 3.01 if it's actually a float, is there any way you can do this through some code? There isn't really a simple answer Integral values do have exact representations in the float and double formats. So, if it's really already integral, you can use: f == floor(f) However, if your value is the result of a calculation which at one point involved any sort of non-zero fractional part, then you will need to be concerned that you may have something very