+ 1

How do I use floating numbers?

can anyone give me an example of how to properly use floating numbers.

9th Jan 2017, 5:33 AM
matt
matt - avatar
10 Respostas
+ 2
What is your question? What stops you from using them the same way as integers?
9th Jan 2017, 6:02 AM
Dao
Dao - avatar
+ 2
Floats are used for decimal numbers. Generally for precision it is better to use Double. Long nor Int can hold decimal places where float and double can.
9th Jan 2017, 7:34 AM
Spyke Olsen
Spyke Olsen - avatar
+ 2
float num = 3.5f for example
9th Jan 2017, 3:18 PM
Spyke Olsen
Spyke Olsen - avatar
+ 1
I'm just not sure how to use them. what symbol is a floating number in a string? I apologize I just started
9th Jan 2017, 6:05 AM
matt
matt - avatar
+ 1
how would I write a floating number then ?
9th Jan 2017, 3:14 PM
matt
matt - avatar
0
How would I write System.out.println(3 + 2 + 1 - 5 + 4 % 2 - 1 / 4 +6) using floating numbers?
10th Jan 2017, 12:02 AM
matt
matt - avatar
0
there's no reason for using a floating number there. it's an integer. I'm not sure I'm picking up on the fascination with floating numbers here. it's just a data type and you declare and utilize it like any other, it just happens to store a decimal as well.
10th Jan 2017, 12:12 AM
Spyke Olsen
Spyke Olsen - avatar
0
if I calculated that correctly it comes out to 6.5. I'm just trying to figure out how to write them properly. I'm lost
10th Jan 2017, 12:18 AM
matt
matt - avatar
0
No its 7.0. There's no difference writing them as opposed to any other variable such as int, char etc. try this: public class main { public static void main (String[] args) { float num; num = 3 + 2 + 1 - 5 + 4 % 2 - 1 / 4 + 6; System.out.print (num) } }
10th Jan 2017, 12:26 AM
Spyke Olsen
Spyke Olsen - avatar
0
ah okay. single enough. thank you
10th Jan 2017, 12:46 AM
matt
matt - avatar