integer

Cast Enumeration Value to Integer in Delphi

拟墨画扇 提交于 2020-06-11 03:06:44
问题 Is it possible to cast/convert an Enumeration Value to Integer in Delphi? If yes, then how? 回答1: This is called out explicitly at the documentation for enumerated types: Several predefined functions operate on ordinal values and type identifiers. The most important of them are summarized below. | Function | Parameter | Return value | Remarks | |----------|:-----------------------------------------------------:|----------------------------------:|-----------------------------------------------

How do I not raise a Python exception when converting an integer-as-string to an int

六眼飞鱼酱① 提交于 2020-06-09 04:00:31
问题 I have some HTML I am trying to parse. There are cases where the html attributes alone are not going to help me identify the row type (header versus data). Fortunately, if my row is a data row then it should have some values that can be converted to integers. I have figured out how to convert the unicode to an integer for those cases that it is possible to make the conversion. I am struggling to write the logic to move past the cells that the conversion will not work because the cell has

How to convert Int to Hex String in Kotlin?

淺唱寂寞╮ 提交于 2020-06-08 04:40:33
问题 I'm looking for a similar function to Java's Integer.toHexString() in Kotlin. Is there something built-in, or we have to manually write a function to convert Int to String ? 回答1: You can still use the Java conversion by calling the static function on java.lang.Integer : val hexString = java.lang.Integer.toHexString(i) And, starting with Kotlin 1.1, there is a function in the Kotlin standard library that does the conversion, too: fun Int.toString(radix: Int): String Returns a string

How to convert strings with billion or million abbreviation into integers in a list

天大地大妈咪最大 提交于 2020-05-26 10:14:47
问题 i have few string items which are the numbers with billion or million abbreviation in a list: list = ["150M", "360M", "2.6B", "3.7B"] I would like to use a syntax that could convert those string items into integers counted in thousands (e.g 150M > 150,000, 3.7B> 3,700,000 ), thanks 回答1: You can use list comprehension with a dict mapping: l = ["150M", "360M", "2.6B", "3.7B"] m = {'K': 3, 'M': 6, 'B': 9, 'T': 12} print([int(float(i[:-1]) * 10 ** m[i[-1]] / 1000) for i in l]) This outputs:

How do I use Java functions to write a program that determines whether 4 integers entered by a user form a square or a rectangle?

假如想象 提交于 2020-05-24 07:48:10
问题 I am a student studying an online course in computer programming. So far, I seem to be doing well throughout the Spring semester. However, I was assigned homework this week that is designed to test my knowledge of Java functions. I am supposed to write a program that asks a user to enter 4 integers, then determines whether those 4 entries form a square or a rectangle. If the 4 entries do make a square or rectangle, then the supposed program has to calculate its perimeter. The output is

Swift: Check which value in NSArray is closest to another given value

有些话、适合烂在心里 提交于 2020-05-16 05:01:28
问题 Lets say I have an array var values:[CGFloat] = [-12.0, 450, 300] I need to find out which of these numbers is closest to a given value, say var givenValue:CGFloat = 64 Is there an efficient way to find out which object in the array is closest to 64? I know you can do something like this: if abs(values[0] - 64) < abs(values[1] - 64) && abs(values[0] - 64) < abs(values[2] - 64) { println("values[0] is the closest to 64) } But this will result in several if-statements and seems inefficient.

Why is Firestore rounding 64 bit integers?

拈花ヽ惹草 提交于 2020-05-09 06:22:51
问题 I'm trying to store 64 bit integers from a python program in my Firestore database. The problem is that it seems like the last digits are rounded off. doc = db.collection('questions').document('0MPvbeTEglD9lbpDq6xm') ints = [9223372036854775807, 9223372036854775533, 9223372036854775267] doc.update({ 'random': ints }) When I look in the database they are stored as: random = [9223372036854776000, 9223372036854776000, 9223372036854775000} According to the documentation 64 bit signed integers are

Python: __add__ and +, different behavior with float and integer

我们两清 提交于 2020-05-08 08:49:37
问题 When adding an integer value to a float value, I realized that __add__ method is working fine if called on float, such as this: >>> n = 2.0 >>> m = 1 >>> n.__add__(m) 3.0 but not if called on an integer: >>> m.__add__(n) NotImplemented At first I thought that __add__ was just being implemented differently for int and float types (like float types accepting to be added to int types, but not the opposite). Then I noticed that everything works fine if I use the + operator instead: >>> n + m 3.0

Scala Divide two integers and get a float result

纵然是瞬间 提交于 2020-04-29 06:22:17
问题 If I do the following println(3/4) >0 I would like to get a decimal answer instead of an integer. Because of the way I am printing in my actual code I would prefer to cast within the println if that is possible. 回答1: If you're typing the number, just type at least one of them as a float (I assume you mean Float not Double ): println(3f/4) If you already have the numbers in variables, convert at least one of them with toFloat val x = 3 println(x.toFloat/4) (In each case, if you have at least

How to Cast Integer Value to Pointer Address Without Triggering Warnings

女生的网名这么多〃 提交于 2020-04-13 03:47:11
问题 I have the following variable uint32_t Value = 0x80 0x80 represents an address in the memory e.g. // Write 2 at address 0x80 *(uint32_t*)((uint32_t)0x80) = 2; How can i cast Value to a Pointer, so it points to 0x80? uint32_t *Pointer = ?? Value; This: (uint32_t*)(uint32_t)Value; returns: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast] 回答1: To handle integer to object pointer conversion, use the optional integer uintptr_t or intptr_t types. Function pointers are