+ 1
How do I use floating numbers?
can anyone give me an example of how to properly use floating numbers.
10 Respostas
+ 2
What is your question? What stops you from using them the same way as integers?
+ 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.
+ 2
float num = 3.5f
for example
+ 1
I'm just not sure how to use them. what symbol is a floating number in a string? I apologize I just started
+ 1
how would I write a floating number then ?
0
How would I write
System.out.println(3 + 2 + 1 - 5 + 4 % 2 - 1 / 4 +6)
using floating numbers?
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.
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
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)
}
}
0
ah okay. single enough. thank you