FAQ Database Discussion Community


How to get 1 digit interger number in a double number in Postgres SQL?

postgresql,int,rounding
In Postgres SQL: Is it possible to get 1 digit number from a double number? For example: I have 27/10 = 2.7 I WANT TO GET the number "2" only (as number not string) I tried to convert 2.7 into integer but it will be rounded into 3. How can...

Oracle and Entity Framework 6: Int32 returned as number

c#,oracle,entity-framework,asp.net-web-api,int
Folks, I have a database-first project in EF6 against an Oracle DB, and I have specified in the model that certain columns should be Int32s. However, when the Web API payload is returned, those properties are returned as Numbers, such as 58.0, 3.0, 486.0 and so on... which makes thr...

Segmentation Fault if I don't say int i=0

c,arrays,segmentation-fault,initialization,int
void removeVowels(char* array){ int i,j,v; i=0; char vowel[]={'a','e','i','o','u'}; while(array[i]!='\0') { for(v=0;v<5;v++) { if (array[i]==vowel[v]) { j=i; while(array[j]!='\0') { array[j]=array[j+1]; j++; } i--; break; } } i++; } } in function removeVowels() if I don't include i=0; and just say int i; why does it give segmentation fault? Isn't it automatically...

Converting a integer to char by adding '0' - what is happening?

c,arrays,string,char,int
I have a simple program like this: #include <stdio.h> int main(void) { int numbers[] = {1, 2, 3, 4, 5}; char chars[] = {'a', 'i'}; char name[] = "Max"; name[1] = chars[1]; printf("name (before) = %s\n", name); name[1] = numbers[1]; printf("name (after) = %s\n", name); return 0; } Compiling and...

Add and print multiple char in C [closed]

c,char,int,add,scanf
I'm creating a Dice Game, where the user rolls 3 dice and gets some random outputs (up to integer 6). My next step is to add those 3 values obtained and get its sum. How do I achieve this? Any suggestion would be helpful. Here's my source code: //Roll-a-dice Game!...

How to change ints in file in java?

java,file,int,export
I am making a simple game in java as my first project but I ran into a problem. In class Undead_Menu, I have been trying to make it so that every time the user chooses the action number one in the while(menuRun) loop,the ints food and water will go will...

Increment number in string C++ [duplicate]

c++,string,int,increment
This question already has an answer here: Converting an int to std::string 7 answers I'm trying to increment the name of the file based on the number associated with the filename. If I make the variable postFix an int type, it gives an error (understandably) since I can't concatenate...

How do char and int work in C++

c++,char,integer,int
May be I'm going to ask a stupid question, but I want to confirm that how char works? Let me explain with examples what i want to ask. Let suppose I declare a char variable and then input 6 or any integer character. #include <iostream> using namespace std; int main(){...

Object of type int is not iterable

python,int,iteration
Here is my code: NUM = 3 A = [1,5,6,2,8,4,3,2,5] B = [] m = [] check = False summ=0 n = len(A) / NUM while check == False: for i in A: if A.index(i) >= n: B.append(m) m = [] n *= 2 m.append(i) B.append(m) for j in B:...

Adding a int variable to a Label and give it +1

c#,int,var,counting
I'm busy with an maze and i currently run on this problem. I want when ever someone hits the wall he uses the method Movetostart and i want to let it count with the var death. So far i got this. int death = 0; private void MoveToStart() { Count.Text...

Parse a date from a text file and convert the month to a number

java,string,int,data-type-conversion
I have a text file display the following: Date Opening Closing 6-Mar-2006 11022.47 10958.59 9-Jun-2006 11005.66 10972.28 7-Dec-2006 10957.31 10980.69 28-Feb-2006 11096.75 10993.41 8-Mar-2006 10977.08 11005.74 How can I read in this file and convert all the months in String to month in int display. "Mar" to 3, "Jun" to...

Converting floating point numbers to integers, rounding to 2 decimals in JavaScript

javascript,floating-point,int
What's the best way to perform the following conversions in JavaScript? I have currencies stored as floats that I want rounded and converted to integers. 1501.0099999999999909 -> 150101 12.00000000000001 -> 1200...

Java method returns double | int

java,int,double,primitive
I need a method that will accept String number as a parameter and return double if it has a remainder, or int if it is decimal. I wrote such code: private double convertToNumber(String number) { double d = Double.parseDouble(number); if (d % 1.0 == 0) { return Integer.parseInt(number); } else...

Weird error comparing ints [duplicate]

java,android,integer,int,compare
This question already has an answer here: Why does 128==128 return false but 127==127 return true in this code? 4 answers I have a weird weird weird weird error, first of all here the class which give me the error public class SpeciePesci { public static final SpeciePesce[] specie...

Find out if you're reading int or double using fscanf

c,parsing,int,double,fscanf
I have a text file that I want to read using C. It contains lines in this format: %d %d (%d or %lf). An example of 3 lines: 1 0 44 2 0 84.13 3 1 15.07 But the last number can be either int or double, arbitrary. How can...

java convert string to int and remove trailing zeros

java,string,arraylist,int,zero
Hi everyone I am currently trying to convert a string to an arrayList in reverse and then remove any trailing zeros eg "001203" converts to (3,0.2,1,0,0) and then (3,0,2,1) my code is currently public convert(String nums) { List = new ArrayList<Integer>(); // create arraylist for (int i = nums.length(); i...

Convert from bin to int/char without loosing leading “0”

python,int,bin
Is there anyway that >>> int('0000001',2) 1 Could save the leading 0s ? What I want to do is, with a huge string of bits, in 8 and 8 bits I would convert to int, and then to char, and write it all in a file. Later I would want...

Sending int from java to c

java,c,sockets,tcp,int
I'm trying to send 5 ints from a java server to a c client. Here is my java code : class Server { public static void main(String args[]) throws Exception { ServerSocket welcomeSocket = new ServerSocket(8080); while(true) { Socket connectionSocket = welcomeSocket.accept(); System.out.println("welcomeSocket.accept() called"); DataOutputStream outToClient = new DataOutputStream(connectionSocket.getOutputStream()); outToClient.writeInt(1);...

Convert String to the name of a array in another class

java,arrays,string,class,int
I'm a amateur programmer and I'm wondering if it's possible to solve a problem in a specific way. public class Stats { public static int[] Hero = {20, 20, 10, 10, 10}; public static int[] Villain = {20, 20, 10, 10, 10}; public static void name(int[] name) { //If you...

Swift - generate random Integer between 0.1 and 0.6

ios,swift,time,int,delay
I'm having trouble with Swift trying to generate a random number between 0.1 and 0.6 I want to introduce a micro delay into a simple game to make it look like the iPhone is having to "think" before responding. I have found various snippets to generate a random number (none...

adding commas to integers in C# [duplicate]

c#,int,comma,spacing
This question already has an answer here: .NET String.Format() to add commas in thousands place for a number 14 answers I'm trying to make a number guessing game that prints only to the console so far, problem is my knowledge and problem solving is in its infancy and I...

Store int in 2 chars

c,casting,char,int
Quick question: Since int is 2 bytes and char is 1 byte, I want to store an int variable in 2 char variables. (like bit 1 - 8 into the first char, bit 9-16 into second char). Using C as programming language. How can I achieve that? Will something like:...

Printing Int variable in Float format [duplicate]

c,gcc,int,printf,format-specifiers
This question already has an answer here: What is printf's behaviour when printing an int as float? 3 answers I'm using gcc to compile this: int a=1; printf("%d\n",a); printf("%f\n",a); printf("%f\n",(float)a); I get: 1 0.000000 1.000000 Why does the implicit conversion give a wrong output?...

convert very big exponential to decimal in c#

c#,int,exponential
5.35754303593134E+300 to 53575430359313400000000000000000000 ... 000000000 Can anyone do this because this number is very large? I have tried: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApplication2 { class Program { static void Main(string[] args) { double s = double.Parse((System.Math.Pow(2, 999)).ToString(), System.Globalization.NumberStyles.Float); Console.WriteLine("value={0}", s); Console.ReadKey(); } }...

User input to store in nested lists with int conversion - Python

python,int,append,nested-lists
I need user input to be stored in a nested list of the form A = [[a, b, c], [d, e, f]]... and so on, based on a number of nested lists that the user desires. a, b, c, ... are integers; so I need to convert the user input...

Using Floor and Int in a computation

int,fortran,floor
I am using a calculation to locate a base pixel. Seems to me that the two calculations for i and j are equivalent (i.e. i==j is always true) when I tried a few examples. Is this always true? i = (int ((x - xmin) / a)) + 1 j =...

Convert Integer to Unsigned Long

c,sockets,int,unsigned-integer
Trying to use the function htonl() for a program that sends an init message to a server, along with an integer value, say 5. However, htonl() needs the following uint32_t integer hostlong How can I convert 5 to an unsigned integer?...

Making simple mathematical application giving error on loop

c#,arrays,math,for-loop,int
Im trying to make an auto solve for this math: __ + __ + __ = 30, Fill the spaces using (1, 3, 5, 7, 9, 11, 13, 15), you can also repeat the numbers. I made this code: int[] nums = { 1, 3, 5, 7, 9, 11, 13,...

why (int) ( 307.03 * 100) = 30702 [duplicate]

php,types,floating-point,int
This question already has an answer here: Is floating point math broken? 18 answers Today my coworker stumbled on this: $s = floatval("307.03"); $s = $s * 100; echo intval($s); //30702 float value or round($s) return 30703 as expected. I guess it's a problem connected with float to int...

Java: Random number in fixed range excluding specified number

java,random,int
In my (Java Android) game, I spawn coins at random positions. Coins can appear at one of 6 positions horizontally across the screen (2 max per horizontal level). What I do is create a random number between 0 and 5 for the first coin, then I want generate another random...

Int is not convertible to UIInterfaceOrientationMak for supportedInterfaceOrientations()

swift,int,uiinterfaceorientation,swift2,xcode7
I have another problem with Xcode 7. I have tried some research but cannot come up with a solution. The error is Int is not convertible to UIInterfaceOrientationMask. The code below: override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask { if visibleViewController is KINWebBrowserViewController { return Int(UIInterfaceOrientationMask.All.rawValue) } return Int(UIInterfaceOrientationMask.Portrait.rawValue) } Thanks...

Convert div data to a float and present it

javascript,casting,int
So what I tried to do is to get all my divs with class "value" that are in betreturns in my html document, these divs looks like this: <div class="value">$ 0.53</div> what I want my code to do is to get the total value of them all and present the...

Still unsure as to why this integer remains unmodified [duplicate]

java,types,int
This question already has an answer here: Is Java “pass-by-reference” or “pass-by-value”? 54 answers I am learning about References and Datatypes in Java and this particular code is still confusing me. I understand that all of the primitive types in Java are value types (byte, short, int, long, float,...

Array from a seperate object not printing correctly

java,arrays,string,object,int
I have a program that currently I'm trying to create a player with customizable integers. I use this object: public class Player { public String player = null; private int Strength=0; private int Defense=0; private int Magic=0; private int Resistance=0; private int Skill=0; private int Luck=0; public Player(String name, int...

How to compare large string integer values

c#,string,int
Currently I am working on a program that processes extremely large integernumbers . To prevent hitting the intiger.maxvalue a script that processes strings as numbers, and splits them up into a List<int>as following 0 is the highest currently known value list entry 0: 123 (hundred twenty three million) list entry...

Objective C unsigned char to negative int

objective-c,int,unsigned-char
I've to transform unsigned char x = 0xEC in int y = -20 unsigned char x = 0xF0 in int y = -16 if I cast like this (assuming x = 0xF0) int y = (int)x I obtain x = 240 that is the correct decimal representation of 0xF0. Where...

Typecasting int to char, then search array

c,arrays,string,casting,int
I have a problem with typecasting in C. Let me explain my problem first: I have a 2-dimensional array of integers that is filled with numbers from 0-9 (its a sudoku and 0 means a empty space). Then I have a second array and that is a 3-dimensional char array....

How do I square a number's digits?

javascript,numbers,int,square,digit
How do I square a number's digits? e.g.: square(21){}; should result in 41 instead of 441...

Incrementing an integer and initialisation placement having a weird effect?

c,loops,int
I have written the following 'Hangman game'-program in C (was written quick and dirty so don't mind the code too much): #include <stdio.h> int main() { char word[] = "cat"; int amountGuessesAllowed = 5; size_t size = sizeof(word)-1; // -1 to exclude the '\0' char guessedWord[size]; for (int i=0; i<size;...

Haskell length toInteger Conversion

haskell,integer,int,type-conversion,tuples
I have the following pair of Integers: maxCollatz :: (Integer, Integer) maxCollatz = (head $ maximum (map collatzList [1..500]), length $ maximum (map collatzList [1..500])) Since I am a newbie, I don't know how to use either fromIntegral or toInteger to convert length to Integer. I know that length must...

How to generate random number in NetBeans? [closed]

java,netbeans,random,int,generated
I'm trying to generate a random between 1 and 100 in NetBeans, but what I used before in Eclipse isn't working. I can't seem to use Random, as it is underined in red: "cannot find symbol." Please show me how. Random x = new Random(); int n = x.nextInt(100);//random number...

Typecasting int pointer to float pointer

c,pointers,floating-point,int,type-conversion
I'm trying to do the following int a[8]={1,2,3,4,5,6,7,8}; printf("%f\n", *(float *)a); printf("%f\n", *((float *)a+1)); printf("%f\n", *((float *)a+2)); printf("%f\n", *((float *)a+3)); printf("%f\n", *((float *)a+4)); printf("%f\n", *((float *)a+5)); printf("%f\n", *((float *)a+6)); printf("%f\n", *((float *)a+7)); I get 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 The reason why I'm trying to print the...

How can I add an int (minutes) to LocalDateTime.now()?

java,int,add
I want to modify LocalDateTime.now() by adding a certain amount of minutes to it. How do I do that?

C get numeric value from part of string

c,string,int,long-integer,strtol
My task is to get long numeric value from part of char[], where I have the index of its begining and ending. I am just learning C, so it is confusing to me which function works the best in my case.. Lets say im making function getNum(): static char words[100000];...

C++ Can I assign an int by using string::at?

c++,string,int,variable-assignment
In my code I have this: int enemyNumber = numberType.at(0); numberType is a string. The first character in string numberType is '1'. But int enemyNumber instead becomes 48 after that assignment. What is going on and how do I get enemyNumber to become '1'?...

What does '<<' do in a C# integer declaration? [duplicate]

c#,variables,int,operators
This question already has an answer here: C# Left Shift Operator 4 answers In C#, what does the << operator do when used to declare a variable? int layer = 1 << 8; I've tried looking up the operator, but only confirmed what I already understood. I'm not to...

Is there an easy way to convert string of ints to individual ints

java,string,int
I am able to do this: int foo = Integer.parseInt("123"); so that int foo = 123 Given that: String numbers = "1 2 3"; //note the separation by a space if that helps int first= int second= int third= Is there an easy way to write the above so that...

Read input into a dynamic sized int?

c,pointers,int,stdin
I need to read a huge number from the stdin, here is the code i have so far: int main() { int x; int* n1 scanf("%d", &x); // I get the number of digits the integer will have n1 = malloc(x * sizeof(int)); // I resize the integer pointer }...

Python – Have a variable be both an int and a str

python,string,int,primes
Here is my code: def retest2(): print "Type in another chapter title! Or type \"Next\" to move on." primenumbers2() def primenumbers1(): print "--------------------------------------------------\nChapters in books are usually given the cardinal numbers 1, 2, 3, 4, 5, 6 and so on.\nBut I have decided to give my chapters prime numbers 2,...

Why does program provide -143155…when I only switched from int to double? [closed]

c,int,double
Why does this code give a completely wrong answer if I use float or double but not int? //C How to Program Exercises 2.33 #include <stdio.h> #include <conio.h> double dailyDrivingCost(double miles, double costPerGallon,double averageMilesPerGallon); int main(void){ double a,b,c,d,e; printf ("Please enter the number of miles daily\n"); scanf("%lf",&a); printf ("Please enter...

Convert Character to Int in Swift 2.0

swift,int,character,swift-playground,swift2
I just want to convert a character into an Int. This should be simple. But I haven't found the previous answers helpful. There is always some error. Perhaps it is because I'm trying it in Swift 2.0. for i in (unsolved.characters) { fileLines += String(i).toInt() print(i) } ...

Cannot convert int {Class}::* to int*

c++,casting,int
When I try to call a function, passing in a reference to my variable which has the type int, to the function which takes a type of int, I get an error that seems to point out that the int is the type of the class it was declared in,...

How do I get my logic in this Java program to make my loop work?

java,if-statement,while-loop,int,logic
I've made this java program to find the two smallest integers as inputted by the user. I think I'm pretty much just about there except there is one issue with my logic. I'm not sure what to set values: int min, min2; to where the rest of my program would...

Jquery, Javascript click && value

javascript,jquery,if-statement,click,int
how do I check inside jquery if a button is clicked and if the variable test has an integer of 1? I have done this so far. $(".bx-next").click(function() && (test == 1){ $("#step_1").text("Hello world!"); }); ...

Objective C converting NSData with hex value to int

objective-c,int,nsdata
I have a NSData with a hex value inside e.g. <EC>. Now I need to convert this value into an int variable to get int x = -20. Ideas?...

In Java, why isn't nextInt() retrieving every number from this text file?

java,matrix,int,java.util.scanner
public GameofLife(int gen) { generations = gen; life = new boolean[20][20]; try { Scanner pablo = new Scanner(new File("life100.txt")); pablo.nextInt(); //eliminate 100 (number of files in the list) while (pablo.hasNextInt()) { life[pablo.nextInt()][pablo.nextInt()] = true; } } catch(Exception e){} out.print(Arrays.deepToString(life)); } I'm trying to read in 100 pairs int coordinates...

How can I convert Int32 to Int in Swift?

swift,core-data,int,type-conversion
It should be easy but I can only find the reverse conversion. How can I convert Int32 to Int in Swift? Unless the problem is different? I have a value stored in Core Data and I want to return it as an Int. Here is the code I am using,...

binary operator += cannot be applied to two Int operands

swift,struct,int
I'm creating a simple struct. struct Expenses { var totalExpenses:Int = 0 func addExpense(expense: Int) { totalExpenses += expense } } It produce error at the beginning of line totalExpenses += expense The error message is binary operator += cannot be applied to two Int operands. Why I am getting...

How to divide a decimal MIDI pitch-bend value into 2 separated 7 bit values correctly?

c,int,midi,7bit
I'm trying to make a sort of custom midi player, to do so I'm using an array that already has memorized correctly the midi messages data like this: int array[3000][4]={{time,status,data1,data2},{...},...} when I want my program to send the midi message (so that it can be played) I call this array...

Printing an int value obtained from user

c,printing,int,scanf,value
The problem is at the age part, the compiler does not give me any errors but when I run it it prints a random number for int age printf("Enter your name:"); scanf(" %s",&name1); int age; printf("\n\nHow old are you?"); scanf(" %d",&age); char gender; printf("\n\nEnter your gender[Male/Female]:"); scanf(" %s",&gender); char confirmation;...

Convert int to Glib::ustring w/o stringstream

c++,int,glib
I need to convert an integer to a Glib::ustring, but I don't want to use stringstream. Not that there's anything inherently WRONG with stringstream, but I don't want yet another library just to accomplish such a simple task. My first instinct is to write a function with a big 'ol...

Calculating time for any sum to double, at a given rate of interest compounded annually

c++,while-loop,int,double
I was trying to write a program that calculates the time it takes for any sum of money to double at a given rate of interest compounded annually. When I run this program, I have found that the loop is not exiting the counter is incremented endlessly with the sum...

Why the division of two integers return 0.00? [duplicate]

c,floating-point,int,printf,format-specifiers
This question already has an answer here: printf(“%f”, aa) when aa is of type int [duplicate] 2 answers Every time I run this program I get different and weird results. Why is that? #include <stdio.h> int main(void) { int a = 5, b = 2; printf("%.2f", a/b); return 0;...

Adding two integers in the debugger gives unexpected output

int,lldb,arithmetic-expressions
I feel silly asking this, but I've debugged this as far as I can. I'm adding two integers together and am getting non-deterministic random letters as output. Any idea what's going on? ...

Is it possible to differentiate between 0 and -0?

c++,int,zero,negative-number
I know that the integer values 0 and -0 are essentially the same. But, I am wondering if it is possible to differentiate between them. For example, how do I know if a variable was assigned -0? bool IsNegative(int num) { // How ? } int num = -0; int...

Arduino int to String conversion

c++,string,arduino,int
I have this code: String c = String(BTLEserial.read()); char relevant = c.charAt(0); Serial.println(relevant); where BTLEserial.read() returns type Int. I'm converting that to a String, in the first line so that I can use the charAt function on it in the next. When I send my Bluetooth "0000", my println(relevant) prints...

C++ string.length() Strange Behavior

c++,string,int
I just came across an extremely strange problem. The function I have is simply: int strStr(string haystack, string needle) { for(int i=0; i<=(haystack.length()-needle.length()); i++){ cout<<"i "<<i<<endl; } return 0; } Then if I call strStr("", "a"), although haystack.length()-needle.length()=-1, this will not return 0, you can try it yourself......

What does it mean when you assign int to a variable in Python?

python,variables,int,type-conversion
i.e. x = int I understand that this will make x an integer if it is not already one, but I'd like to understand the process behind this. In particular, I'd like to know what int is (as opposed to int()). I know that int() is a function, but I'm...

Char to Int - C++

c++,list,struct,char,int
I know there are already answered questions about it, but I have read most of them and still couldn't solve my problem. I have a program that will read notes, keep them in a list and give options to the user to delete, change, or select a specific note. I'm...

Dynamic Array Size in C++

c++,arrays,dynamic,int,sizeof
I am looking for a way to dynamically set the size of an integer array depending on the passed parameter. For example this in pseudocode: int MyFunction(int number) { int myarr[amount of digits in number]; } So when the input is 13456 then the int array[] size should be 5....

Maple : integer equation without explicit delimiters

int,maple
I would like to calculate an integer in Maple without explicit delimiters. For example, I would like to have the result of this formula : int(cos(a+b*x),x=0...t)) where t referred to none number. The error message is : "Error, unable to match delimiters". Is there any solution ?...

Last two bits in a BitArray of length 4 are being ignored when converting to int

c#,binary,int,bit,bitarray
Consider the following BitArray: BitArray bitArray = new BitArray(new Boolean[] {true, true, false, false}); and in binary equals: 1100 Now I want to convert this to an int and have tried to use the methods described on this page: How i can convert BitArray to single int? However, both these...

Integer not comparing equal to its value

c++,int,comparison-operators
I've got a piece of code I am trying to debug, which is producing bizarre results. An integer, which very clearly contains the value six, compares false to the literal 6. In my code, this code: int allGreen = 0; int index = 0; while (ch->fb[index]->selection_color() == FL_GREEN) { ++allGreen;...

Int crash my app

android,math,int
I am wondering if there is any issue with the line below? int b1 = Integer.valueOf(selection.getText().toString()); int b12 = (b1*100); result.setText(Integer.toString(b12)); I have isolated the line to the line below: int b1 = Integer.valueOf(selection.getText().toString()); I am intending to use the b1 int value to do a simple math which is...

Comparison between unsigned int and int without using cast operator

c,int,compare,type-conversion,unsigned-integer
everyone I looked aroud there exist an topic about my question. I could not find . unsigned int x = 5; int y = -3; if(y<x) func1(); else func2(); func2 is called . But i want to call func1 . I know that, I must use cast operator by using...

Why am I printing out 'System.Int32[]' instead of my array of numbers?

c#,int,int32
I am trying to print out my array of numbers that I have assigned to a particular array. My algorithm for choosing numbers consists of choosing a random number that is not a duplicate and storing it inside the array. Pretty simple really, but I have no idea as to...

Using int, double and long in calculation of powers

java,int,double,long-integer
I'm having trouble figuring out when to use int, double and long. I'm working on calculating the power of an integer and return the result as long as the power provided is not a negative number. For the assignment, I'm required to use the following code to start: public static...

Why GraphicsContext uses methods with double params?

java,swing,javafx,int,double
I'm moving from swing to javafx. I wondered why GraphicsContext uses methods with double params. For example fillRect(double x, double y, double w, double h) unlike swing has methods drawRect(int x, int y, int width, int height). Should I do all my calculations in double?...

How to work with hex() in python?

python,python-2.7,int,hex
I've problem with hex() in python 2.7 I want to convert '0777' to hex with user input. but it have problem with using integer with user input. In [1]: hex(0777) Out[1]: '0x1ff' In [2]: hex(777) Out[2]: '0x309' In [3]: z = raw_input('enter:') enter:0777 In [4]: z Out[4]: '0777' In [5]:...

“(int)Math.ceil(double)” always return 1 when values is greater than 0

java,casting,int,double,rounding
I'm creating an Android app and I need to calculate the movement speed of the device. I do this by taking an average of some earlier locations' speeds. However, I need the speed to be in km/h as an int, so I use (int)Math.ceil(speedAsDouble) However, this always equal to 1,...

objective c convert int to unsigned char hex

objective-c,char,int,hex
I've to convert int x = 4 in to unsigned char y = 0x04 int x = 0 in to unsigned char y = 0x00 int x = -4 in to unsigned char y = 0xFC int x = -8 in to unsigned char y = 0xF8 and so on,...

How to get an integer as a string [duplicate]

c,string,int
This question already has an answer here: How to convert integer to string in C? [duplicate] 3 answers I'm trying to return a string, which is the year. This code is no where near my GUI layer, as such I'm attempting the following #define COMPANY_COPYRIGHT "Copyright © " +...

Wrong value in NSNumber, CFNumberType not defined

objective-c,core-data,int,nsnumber
All, I have created a datamodel with 3 field: - beingPlayed type int16 - position type int16 - playedBy type int16 I have generated a class for it. Tile.h @property (nonatomic, retain) NSNumber * beingPlayed; @property (nonatomic, retain) NSNumber * playedBy; @property (nonatomic, retain) NSNumber * position; Tile.m @dynamic beingPlayed;...

Error: cannot find symbol - Java compile error

java,int,symbol
I've been looking at this for a while now, and I'm sure the fix is right in front of me but I'm just blind to it. Someone care to point out why my int i is giving me an error? CacheDownloader class: public static void main(String[] args) { String strFilePath...

TypeError: 'int' object is not subscriptable (python)

python,object,matrix,int,multiplication
I'm having problems making a matrix multiplication algorithm in python3. This is the code: def matrixMult(m1, m2): result = [[0 for x in range(len(m1))] for x in range(len(m2[0]))] # Iterate through rows of m1. for i in range(len(m1)): # Iterate through columns of m2. for j in range(len(m2[0])): # Iterate...

How to get last array object as int

ios,objective-c,arrays,object,int
How can I get the last object from an array as an int, for example if I have 20 objects in the array, how can I get the last object as an int variable that = 20. Or if the array had 999 objects, the last object int would =...

Convert float number to int or string

php,string,floating-point,int
I am retrieving a Facebook ID and I am getting a float: float(1.1262850591603E+16) How could I convert it to int (or string) to use it here? http://graph.facebook.com/1.1262850591603E+16/picture I tried intval function, but it returns a wrong result: <?php intval(1.1262850591603E+16); // returns -1062487752 ?> Thank you!...

How to use int of app delegate in other class in IOS?

ios,objective-c,int,appdelegate
Can someone help me in answer below 3 question? It will help me to solve my problem. How to declare int in app delegate. How to transfer this int value to other class. How to NSLog this value in other class. ...

Parsing int from string produces incorrect result

java,string,parsing,int
I'm trying to use parseInt() to get an int from a String and I read about radix so I'm passing 10 as the second parameter: String str= "02"; int test= Integer.parseInt(str, 10); System.out.println("Should be 2:" + test); The output is actually 0. What's gone wrong here?...

C/C++ How to convert back int to string (a word)?

c,string,int,fscanf
In C I'm reading a string from a txt file, for example the string "hello", so i have my: F=fopen("text.txt","r"); fscanf(F,"%s\n",string); Now, if i want to convert this string to hex and decimal, i can do something like this: for (i=0; i<strlen(string); i++) { sprintf(st, "%02X", string[i]); //Convert to hex...

What do I get if I declare an array without a size in global scope?

c,arrays,int,global-variables
In one of the answers in Tips for golfing in C, I saw this code (ungolfed version): s[],t; main(c){ for(scanf("%*d "); ~(c=getchar()); s[t++]=c) putchar(s[t]); } I think that the above program exhibits UB (but who cares in code golf?). But the thing that I don't understand is the s[] in...

c++ - how to convert char to int?

char,int,printf
I try to write a function who convert a string to an integer (like atoi). I don't see why my function "convertir" don't print my variable "res " whereas "test 1 " "test 2"... "test 4" is printed. I let you look at my code and if you see something...

Recursive random password generator

java,recursion,random,passwords,int
I am attempting to write a recursive password generating program in java, but instead of returning one randomly generated password, the console spits out every combination of passwords and just keeps going. *Also, I'm required to have at least one capital letter in the password, which is why I am...

C - how to keep variable

c,static,int
I would like know how I can keep the text in the txt variable? I would like to keep it unitl my function will end - I think it's called static int #include <stdio.h> #include <stdlib.h> int main() { char buf[1024]; char txt[100]; printf("Insert a text: "); fgets(txt, 100, stdin);...

Trying to go through a 2d array, and not getting the correct values?

java,if-statement,multidimensional-array,int,paint
So currently I am making a maze game, and of course for it to be a maze game it has to have walls. Walls need to stop the player from going over them. I am having a problem checking for collision. It works in some places, and others not. My...

Sql convert string of numbers to int

sql,sql-server,string,int
I want to select either week days or a full week depending on a parameter. I was looking at using a case statement to do the following, but I don't know how to convert a string of number to a value that can be passed as integers. Im probably doing...

Why is my char printing as a number instead of a character?

java,char,int
As per the Java ternary operator expression ? statement1 : statement2, if expression is true then statement1 will be executed, if expression is false then statement2 will be executed. But when I run: // some unnecessary codes not displaying char y = 'y'; int i = 0; System.out.print(false ? i...

Integer in String with 1 or 2 digits

java,regex,string,int
sorry I don't know if you understand what I want to do and I am also not 100% sure if it can be done by regex, but maybe there is a better solution than the one I have in my mind. I want to create a function which gets a...

How does C treat char sums?

c++,c,char,int
When I'm in C++, and I call an overloaded function foo, like so: foo('e' - (char) 5) it can output "this is a char" or "this is an int" based on the type result. I get "this is an int" from my program, like this: #include <iostream> void foo(char x)...

Treating a string as an integer

python,string,int
I'm trying to make a very simple Blackjack game. When you get dealt two cards, everything's okay if they're both integers or strings, but I get an error if the two cards dealt are a string and an integer. How can I make it so that if you get dealt...