numbers

Inputting a number then reversing it

*爱你&永不变心* 提交于 2020-01-04 06:28:28
问题 Ok so I wrote a program which asks user to input a number and then reverse it. I was successful in it however the program does not reverses numbers that end with a 0. for example if i enter 1234 it will print out 4321 however if i input 1200 it will only output 21. I tried converting the number that is to become output into string. Please help me understand where I am doing it wrong. Just remember I am a beginner at this :). Below is my code. import java.util.*; public class ReverseNumber {

Make EditText accept non-English numbers

时间秒杀一切 提交于 2020-01-04 05:22:27
问题 I made a very simple app that involves only numbers and there is no need to make different locale folders or anything. When I test the app, the EditText will take numbers when the keyboard language is English, but when I change the keyboard to other languages it does not work! pressing a number will not show up in the EditText . Is there a way to make the EditText take universal numbers regardless of the language? 回答1: I think it will work <EditText android:inputType="numberSigned

Store Big Price value in database along with Decimal Point in SQLite Database

落花浮王杯 提交于 2020-01-04 05:08:34
问题 May be my question is silly, But I didn't find any Solution for this. Actually, I want to Store Big Price Amount i.e. 9999999999.99 in Sqlite Database and want to retrive it back. I tried with TEXT, DOUBLE, REAL, LONG Datatypes. Unfortunately when i do this, it returns me back unwanted value i.e. 9.999999999.. . Please suggest me if you have solution for this, or guide me. 回答1: The defined column type affinity TEXT , REAL , NUMERIC , VARCHAR , RUMPLESTILTSKIN ( yes it works ), has little

How can I verify if a string is a valid float? [duplicate]

耗尽温柔 提交于 2020-01-04 02:54:36
问题 This question already has answers here : Check if string is a real number (4 answers) Closed 6 years ago . What I want to do is to verify if a string is numeric -- a float -- but I haven't found a string property to do this. Maybe there isn't one. I have a problem with this code: N = raw_input("Ingresa Nanometros:"); if ((N != "") and (N.isdigit() or N.isdecimal())): N = float(N); print "%f" % N; As you can see, what I need is to take only the numbers, either decimal or float. N.isdecimal()

Octave - random generate number

十年热恋 提交于 2020-01-03 17:21:09
问题 I have a simple question about randomly generating numbers in Octave/Matlab. How do I randomly generate a (one!) number (that is either 0 or 1)? I could really use an example. Thanx 回答1: Use rand, which generates a uniform pseudo-random number in the range 0..1, and then test this value against a suitable threshold, e.g. 0.5 for equal probability of 1 or 0: r = rand > 0.5 回答2: You should use randi for integer random numbers: randi(2) - 1 回答3: For the sake of variety, here's another way floor

BitConverter VS ToString for Hex

≯℡__Kan透↙ 提交于 2020-01-03 17:16:13
问题 Just wondering if someone could explain why the two following lines of code return "different" results? What causes the reversed values? Is this something to do with endianness? int.MaxValue.ToString("X") //Result: 7FFFFFFF BitConverter.ToString(BitConverter.GetBytes(int.MaxValue)) //Result: FF-FF-FF-7F 回答1: int.MaxValue.ToString("X") outputs 7FFFFFFF , that is, the number 2147483647 as a whole . On the other hand, BitConverter.GetBytes returns an array of bytes representing 2147483647 in

python中列表中的方法(重点) 列表的基本操作(赋值、删除和分片赋值)

天涯浪子 提交于 2020-01-03 17:12:26
第 7 课: 列表的基本操作(赋值、删除和分片赋值) # 列表的基本操作 # 赋值、删除列表元素、分片赋值 # 1. 列表元素的赋值 values = ["Bill", "Mary", "John"] values[0] = "Mike" values[1] = 10.4 values[-1] = "Joe" # values[-5] = "abc" # 抛出异常 print(values) # ['Mike', 10.4, 'Joe'] # 删除列表中的元素 numbers = [1,2,3,4,5,6,7,8] del numbers[3] print(len(numbers)) # 7 print(numbers) # [1, 2, 3, 5, 6, 7, 8] # 分片赋值 names = ["Bill", "Joe", "李宁","马云"] print(names[3:]) # ['马云'] names[3:] = ["a","b","c"] print(len(names)) # 6 print(names) # ['Bill', 'Joe', '李宁', 'a', 'b', 'c'] name = list("John") # 将一个字符串转化为一个列表 print(name) #['J', 'o', 'h', 'n'] name[2:] = list("e")

Get the next higher integer value in java [duplicate]

喜你入骨 提交于 2020-01-03 14:16:11
问题 This question already has answers here : How to round up the result of integer division? (15 answers) How to round up integer division and have int result in Java? [duplicate] (9 answers) Closed 11 months ago . I know I can use Math.java functions to get the floor, ceil or round value for a double or float, but my question is -- Is it possible to always get the higher integer value if a decimal point comes in my value For example int chunkSize = 91 / 8 ; which will be equal to 11.375 If I

C# numeric base class [duplicate]

岁酱吖の 提交于 2020-01-03 09:01:47
问题 This question already has answers here : Is there a constraint that restricts my generic method to numeric types? (19 answers) Closed 5 years ago . I want to write a C# method that can accept any number. Something like: public static T Sum(T a, T b) where T : number { // (not real code) return a + b; } But I don't see a "number" base class in C#, as exists in most other languages I've used. The numeric value types are IComparable, IFormattable, IConvertible, IComparable, and IEquatable, but

Decimal/double to integer - round up (not just to nearest)

喜夏-厌秋 提交于 2020-01-03 06:48:10
问题 How would you round up a decimal or float to an integer. For instance... 0.0 => 0 0.1 => 1 1.1 => 2 1.7 => 2 2.1 => 3 Etc. 回答1: Simple, use Math.Ceiling: var wholeNumber = (int)Math.Ceiling(fractionalNumber); 回答2: Something like this? int myInt = (int)Math.Ceiling(myDecimal); 回答3: Math.Ceiling not working for me, I use this code and this work :) int MyRoundedNumber= (int) MyDecimalNumber; if (Convert.ToInt32(MyDecimalNumber.ToString().Split('.')[1]) != 0) MyRoundedNumber++; and if you want to