Results 1 to 6 of 6
Thread: decimal calculations?
- 11-17-2008, 03:24 PM #1
Member
- Join Date
- Oct 2008
- Posts
- 40
- Rep Power
- 0
- 11-17-2008, 03:46 PM #2
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Is that getDuration() return an int value? In that case you have to cast it as a float.
Java Code:float a = (float)p.getDuration()/1000000;
- 11-17-2008, 04:16 PM #3
Member
- Join Date
- Oct 2008
- Posts
- 40
- Rep Power
- 0
tried that just now. it still returns 1.0. getDuration returns a long
- 11-18-2008, 07:24 AM #4
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Can you show your code here to see?
- 11-19-2008, 12:40 AM #5
you need something like:
Your use of an integer in the denominator causes the division of "p.getDuration()" to be done as an integer.Java Code:float a = (float)(p.getDuration()/1000000.0);
Floating an integer is still an integer
- 11-19-2008, 03:36 AM #6
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Or yes lol, thanks for the pointing my mistake there. I just code in the message box here.
Similar Threads
-
round to two decimal places
By javaMike in forum New To JavaReplies: 3Last Post: 12-24-2011, 02:01 AM -
numbers with two decimal places
By little_polarbear in forum New To JavaReplies: 8Last Post: 08-27-2008, 11:04 PM -
Why my program cannot calculate the decimal value?
By pearllymary78 in forum New To JavaReplies: 4Last Post: 06-23-2008, 12:52 AM -
Java calculator decimal
By cart1443 in forum New To JavaReplies: 2Last Post: 04-16-2008, 01:19 PM -
Capping decimal places
By Rageagainst20 in forum New To JavaReplies: 1Last Post: 12-20-2007, 09:28 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks