Java is only calculating to once decimal place
- From: rleroux@xxxxxxxxx
- Date: 26 Jan 2007 01:52:44 -0800
I'm doing a calculation with a variable defined as a float.
(e.g. take 5% and add 1)
I should get 1.05
When I print the variable that should hold 1.05, I only get 1.0
Needless to say when I use the variable that should have 1.05 stored,
in the rest of my calculation, I'm getting errounious results (i.e.
cannot divide by 0).
I am inputting a figure (integer) from the that needs to be calculated
as a percent. I store the result in a variable as a float
int entry;
float answer;
answer = 1+(entry/100);
thus if I enter 5...
answer = 1+(5/100)
answer = 1.05
when I have java display answer (System.out.println(answer);) I have
1.0 which thows the rest of my calculation that the above formula is
in, out of whack
I understood floats are suppose to have more than one significant digit?
.
- Follow-Ups:
- Re: Java is only calculating to once decimal place
- From: Nigel Wade
- Re: Java is only calculating to once decimal place
- From: Chris Dollin
- Re: Java is only calculating to once decimal place
- From: Jussi Piitulainen
- Re: Java is only calculating to once decimal place
- From: Gordon Beaton
- Re: Java is only calculating to once decimal place
- Prev by Date: Re: file.exists() timeout?
- Next by Date: Re: Java / SQL Server 2005
- Previous by thread: log display when using ejb
- Next by thread: Re: Java is only calculating to once decimal place
- Index(es):
Relevant Pages
|