Results 1 to 5 of 5
Thread: Java does not read the decimals?
- 08-07-2011, 11:50 PM #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, 12: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, 12: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, 01: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, 09:23 AM #5
- By flpanthers1 in forum New To JavaReplies: 8Last Post: 06-06-2011, 02:27 AM
- By xael in forum New To JavaReplies: 17Last Post: 10-04-2010, 10:14 AM
- By Gold in forum New To JavaReplies: 3Last Post: 12-09-2009, 11:25 PM
- By kushagra in forum New To JavaReplies: 5Last Post: 10-17-2008, 02:13 PM
- By javanewbie in forum New To JavaReplies: 1Last Post: 07-02-2008, 01:58 PM