Results 1 to 5 of 5
Thread: Java does not read the decimals?
- 08-08-2011, 12:50 AM #1
Java does not read the decimals?
Hello. I was going to post this on the Appleta' site, as it's a problem from an applet, but as I overloaded it with threads today and I think it's a general Java problem, I decided to post it here.
Well, the thing is that I've got a varyable named "x", and I set it at 1. Summarizing it all, t when I substract 0.05 from that 1, the applet takes it as 0.
What can I do to solve it and make Java take it as 0.95? Thanks!
PS: if it's a specific problem of applets, tell me and I'll change the thread to the applets' site.
- 08-08-2011, 01:01 AM #2
What you are describing is integer arithmetic. An int variable can only hold whole numbers. If you want floating point numbers define the variable as double.
It has nothing to do with where the code is executed.
- 08-08-2011, 01:39 AM #3Moderator
- Join Date
- Feb 2009
- New Zealand
- Rep Power
Remember that you have to declare (==say whether it's an int or a double etc) a variable before you can assign (==set, add etc) a values to it.
// int foo = 1; double foo = 1.0; foo -= 0.05; System.out.println(foo);
- 08-08-2011, 02:06 AM #4
Learning about primitives should be just about the first thing you learn. How the heck do you get to writing applets without knowing that you need a double or float to hold a floating point number?
- 08-08-2011, 10:23 AM #5
- By flpanthers1 in forum New To JavaReplies: 8Last Post: 06-06-2011, 03:27 AM
- By xael in forum New To JavaReplies: 17Last Post: 10-04-2010, 11:14 AM
- By Gold in forum New To JavaReplies: 3Last Post: 12-10-2009, 12:25 AM
- By kushagra in forum New To JavaReplies: 5Last Post: 10-17-2008, 03:13 PM
- By javanewbie in forum New To JavaReplies: 1Last Post: 07-02-2008, 02:58 PM