Results 1 to 7 of 7
Thread: Percentage/decimal points?
- 01-16-2009, 08:40 PM #1
Member
- Join Date
- Jan 2009
- Posts
- 21
- Rep Power
- 0
Percentage/decimal points?
Erm score_percent is a double type of variable so the result comes out in like xx.xxxxxxxxx% :p Anyway to get rid of some of the decimal places or round?Java Code:score_percent = score/7.0*100.0; score_results.setText("<html>Score: "+score+"/7 <br> That is: "+score_results+"%</html>");
And [CODE]score_percent = (int)score/7.0*100.0;
gives ultra weird errors xDLast edited by Exhonour; 01-16-2009 at 08:43 PM.
- 01-16-2009, 09:41 PM #2
Member
- Join Date
- Sep 2008
- Posts
- 43
- Rep Power
- 0
it's because you're casting a double down to an int and then dividing by a number with a decimal place.
Either remove the decimal place on the 7 and the 100 as you don't need them anyways. or you should just cast the double to a float rather than an int.
- 01-16-2009, 09:48 PM #3
Member
- Join Date
- Jan 2009
- Posts
- 21
- Rep Power
- 0
Hmm
Now it starts to say on the label:
javax.swing.JLabel[,0,0,0x0,invalid,alignmentX=0.0,alignmentY=0.0,bor der=,flags=8388608,ma...
I have no idea what it means lol
Doesnt matter if im using float, int or double...Last edited by Exhonour; 01-16-2009 at 09:53 PM.
- 01-16-2009, 10:26 PM #4
Member
- Join Date
- Sep 2008
- Posts
- 43
- Rep Power
- 0
oh yeah, didn't notice that before, not sure exactly what you're trying to do but I think you need to change the bit that says:
<br> That is: "+score_results+"%</html>");
to:
<br> That is: "+score_percent+"%</html>");
- 01-16-2009, 10:29 PM #5
you can use the number format class or printf
USE CODE TAGS--> [CODE]...[/CODE]
Get NotePad++ (free)
- 01-16-2009, 10:30 PM #6
Member
- Join Date
- Jan 2009
- Posts
- 21
- Rep Power
- 0
Omg what a stupid mistake by me, thanks that helps.
- 01-16-2009, 10:35 PM #7
Member
- Join Date
- Jan 2009
- Posts
- 21
- Rep Power
- 0
Similar Threads
-
get percentage formatting to display 2 decimal places
By gotenks05 in forum New To JavaReplies: 5Last Post: 03-03-2009, 04:57 PM -
Random Points inside a Polygon
By nidhirastogi in forum Advanced JavaReplies: 1Last Post: 09-23-2008, 03:28 AM -
Dubugger points to incorrect source code
By gdias in forum EclipseReplies: 0Last Post: 09-02-2008, 08:07 PM -
given number of points(cordinates) , find max points lie on the same line ?
By Hayzam in forum New To JavaReplies: 2Last Post: 08-24-2008, 12:30 AM -
To get the points on the perimeter of a Rounded Rectangle
By rashibahal in forum New To JavaReplies: 6Last Post: 06-12-2008, 09:14 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks