numbers

Sort a list numerically in Python

ぐ巨炮叔叔 提交于 2019-12-02 02:08:11
So I have this list, we'll call it listA. I'm trying to get the [3] item in each list e.g. ['5.01','5.88','2.10','9.45','17.58','2.76'] in sorted order. So the end result would start the entire list over again with Santa at the top. Does that make any sense? [['John Doe', u'25.78', u'20.77', '5.01'], ['Jane Doe', u'21.08', u'15.20', '5.88'], ['James Bond', u'20.57', u'18.47', '2.10'], ['Michael Jordan', u'28.50', u'19.05', '9.45'], ['Santa', u'31.13', u'13.55', '17.58'], ['Easter Bunny', u'17.20', u'14.44', '2.76']] If you want to return the complete list in sorted order, this may work. This

Why does toPrecision return a String?

匆匆过客 提交于 2019-12-02 02:00:15
View this code: function testprecision(){ var isNotNumber = parseFloat('1.3').toPrecision(6); alert(typeof isNotNumber); //=> string } I would have expected a number. If 'isNotNumber' should be a real number, recasting is the solution: alert(typeof parseFloat(isNotNumber)) //=> number [Edit] thanks for your answers. Precision is not so precise a term I conclude. It can represent the total number of digits of a number, or the number of fractional digits . Most people in the Netherlands (where I come from) think of precision in the 'number of fractional digits'-way. The javascript toPrecision

Does scientific notation affect Perl's precision?

我们两清 提交于 2019-12-02 01:37:27
I encountered a weird behaviour in Perl. The following subtraction should yield zero as result (which it does in Python): print 7.6178E-01 - 0.76178 -1.11022302462516e-16 Why does it occur and how to avoid it? P.S. Effect appears on "v5.10.0 built for x86_64-linux-gnu-thread-multi" (Ubuntu 9.04) and "v5.8.9 built for darwin-2level" (Mac OS 10.6) It's not that scientific notation affects the precision so much as the limitations of floating point notation represented in binary. See the answers to the perlfaq4 . This is a problem for any language that relies on the underlying architecture for

Android number format is wrong somehow, instead of 3.5 I get 3.499999999, why?

為{幸葍}努か 提交于 2019-12-02 01:23:29
I store some data in a database and I read those data with a cursor. All the data are 56.45 , 3.04, 0.03 type, so two numbers after the decimal point. Now I would like to sum them but it doesnt seem to be easy... I get those number with c.getDouble(3) then I add it to the sum variable like: sum+= c.getDouble(4) * multi multi is an integer between 1 and 100. Now my problem is that, after getting the sum variable I get a number like: 59.51999999999999999. I do not post a code, but there is no conversion except a string.valueOf for making the number appear on my widget. So anybody experienced

VBA to remove numbers from start of string/cell

时间秒杀一切 提交于 2019-12-01 23:48:17
I hope you can help. I have a piece of code that is currently removing all the text from the cells in Column G. What I need is for this code to instead of removing the text I would like it to remove the numbers, and I only want it to remove the numbers at the beginning of the string/cell the rest of the data I would like to remain the same. I have attached a picture PIC.1 for betting understanding. PIC1 The code I currently have and I hope can be amended is below and as always any and all help is greatly appreciated . CODE Sub RemoveNonDigits() Dim X As Long, Z As Long, LastRow As Long,

random number guessing game

≯℡__Kan透↙ 提交于 2019-12-01 23:27:49
问题 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

XSL vs Regionalisation/Internationalization Number Formats

北慕城南 提交于 2019-12-01 23:10:28
Is there any regionalisation support built into XSL when it comes to formatting numbers? At present my underlying XML contains numbers in UK/US format, for example 54321.12345. I can do a select sum on this to give me a total in the same format. I can format the number using format-number(54321.12345, '###,###.#####') to give me 54,321.12345. However when I want this to run on a different region setting on my machine such as Central European countries which have the comma seperator as "." and the decimal seperator as "," I want to format my numbers in this way to give me 54.321,12345. Is there

c++ template for conversion between decimal and arbitrary base

随声附和 提交于 2019-12-01 22:59:20
Is there a c++ structure or template (in any library) that allows me to do conversion between decimal and any other base (much like what bitset can do) ? Yes, you can use unsigned int : unsigned int n = 16; // decimal input unsigned int m = 0xFF; // hexadecimal input std::cout << std::dec << "Decimal: " << n << ", " << m << std::endl; std::cout << std::hex << "Hexadecimal: 0x" << n << ", 0x" << m << std::endl; Octal is also supported, though for other bases you had best write your own algorithm - it's essentially a three-liner in C++: std::string to_base(unsigned int n, unsigned int base) {

Create leading zero in Oracle

China☆狼群 提交于 2019-12-01 22:45:54
I am using Adempiere which has database Oracle I have window called Stock Code from table called M_StockCode The fields are Code and Description . Currently, Code data type is Number and Description is Varchar2 I want to input Sparepart with Code 01 , and Body Repair with Code 02 . As I input the data in Adempiere and save it, what will show is Sparepart with Code 1 (without leading zero) I've tried putting LPAD function but it's still failed. How can I put 01 both in Adempiere interface and in database? Any suggestion will be appreciated :) A NUMBER cannot have leading zero, a STRING can. If

Converting calculation string to int in Lua

五迷三道 提交于 2019-12-01 22:32:49
I'm trying to get a string with multiple numbers to a single int like this: x="5+5" --amount of numbers is not constant y=tonumber(x) print(y) The result of this is nil while it should be 10 (int). The only way I could solve this is by first searching all the "+" and "-" with string.find() then cutting it to all the necessary parts and from there just tonumber() . It feels stupid to code at least a hundred rows of code for such a simple problem. tonumber can be used only on a string that is a real number, not an arithmetic expression. You can load the string and run it: x = "5 + 5" func =