Initialize a long in Java

Primitive Data Types – oracle doc says the range of long in Java is -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807. But when I do something like this in my eclipse long i = 12345678910; it shows me “The literal 12345678910 of type int is out of range” error. There are 2 questions. 1) How do I initialize the … Read more

How to convert / cast long to String?

I just created sample BB app, which can allow to choose the date. DateField curDateFld = new DateField(“Choose Date: “, System.currentTimeMillis(), DateField.DATE | DateField.FIELD_LEFT); After choosing the date, I need to convert that long value to String, so that I can easily store the date value somewhere in database. I am new to Java and … Read more

How to printf “unsigned long” in C?

I can never understand how to print unsigned long datatype in C. Suppose unsigned_foo is an unsigned long, then I try: printf(“%lu\n”, unsigned_foo) printf(“%du\n”, unsigned_foo) printf(“%ud\n”, unsigned_foo) printf(“%ll\n”, unsigned_foo) printf(“%ld\n”, unsigned_foo) printf(“%dl\n”, unsigned_foo) And all of them print some kind of -123123123 number instead of unsigned long that I have. 7 Answers 7

Java JDK – possible lossy conversion from double to int

When you convert double to int,the precision of the value is lost. For example, When you convert 4.8657 (double) to int.The int value will be 4.Primitive int does not store decimal numbers.So you will lose 0.8657. In your case,0.7 is a double value(floating point treated as double by default unless mentioned as float-0.7f). When you calculate price*much*0.7 ,the answer is a double … Read more