User Name
Remember Me?
Password
Register
FAQ
Social Groups
Calendar
Search
Today's Posts
Mark Forums Read
Java Forums
»
Java ME
»
CLDC and MIDP
»
decimal calculations?
LinkBack
Thread Tools
Display Modes
#
1
(
permalink
)
11-17-2008, 04:24 PM
arnab321
Member
Join Date: Oct 2008
Posts: 39
Rep Power:
0
decimal calculations?
hi,
when i try this: float a=p.getDuration()/1000000;
System.out.println("a="+a+" actual="+p.getDuration());
p.getDuration() is a number like 1791800
so, a is expected to be 1.7918.
but why does is come as 1.0?
#
2
(
permalink
)
11-17-2008, 04:46 PM
Eranga
Moderator
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 7,513
Rep Power:
11
Is that getDuration() return an int value? In that case you have to cast it as a float.
Code:
float a = (float)p.getDuration()/1000000;
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
Someone helped you?
their helpful post.
Help:
Forums FAQ
|
How To Ask Questions The Smart Way
Resources:
The Java Tutorials
|
Glossary for Java
|
NetBeans IDE
|
Sun Downloads
Web:
WritOnce
Tips:
Is your IDE the best?
|
Which Application Server?
#
3
(
permalink
)
11-17-2008, 05:16 PM
arnab321
Member
Join Date: Oct 2008
Posts: 39
Rep Power:
0
tried that just now. it still returns 1.0. getDuration returns a long
#
4
(
permalink
)
11-18-2008, 08:24 AM
Eranga
Moderator
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 7,513
Rep Power:
11
Can you show your code here to see?
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
Someone helped you?
their helpful post.
Help:
Forums FAQ
|
How To Ask Questions The Smart Way
Resources:
The Java Tutorials
|
Glossary for Java
|
NetBeans IDE
|
Sun Downloads
Web:
WritOnce
Tips:
Is your IDE the best?
|
Which Application Server?
#
5
(
permalink
)
11-19-2008, 01:40 AM
fishtoprecords
Senior Member
Join Date: Jun 2008
Posts: 571
Rep Power:
2
you need something like:
Code:
float a = (float)(p.getDuration()/1000000.0);
Your use of an integer in the denominator causes the division of "p.getDuration()" to be done as an integer.
Floating an integer is still an integer
#
6
(
permalink
)
11-19-2008, 04:36 AM
Eranga
Moderator
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 7,513
Rep Power:
11
Or yes lol, thanks for the pointing my mistake there. I just code in the message box here.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
Someone helped you?
their helpful post.
Help:
Forums FAQ
|
How To Ask Questions The Smart Way
Resources:
The Java Tutorials
|
Glossary for Java
|
NetBeans IDE
|
Sun Downloads
Web:
WritOnce
Tips:
Is your IDE the best?
|
Which Application Server?
Bookmarks
Digg
del.icio.us
StumbleUpon
Google
«
Problem with Midlet back button
|
simple mp3 streaming
»
Thread Tools
Show Printable Version
Email this Page
Display Modes
Linear Mode
Switch to Hybrid Mode
Switch to Threaded Mode
Posting Rules
You
may not
post new threads
You
may not
post replies
You
may not
post attachments
You
may not
edit your posts
BB code
is
On
Smilies
are
On
[IMG]
code is
On
HTML code is
Off
Trackbacks
are
On
Pingbacks
are
On
Refbacks
are
On
Forum Rules
Similar Threads
Thread
Thread Starter
Forum
Replies
Last Post
numbers with two decimal places
little_polarbear
New To Java
8
08-28-2008
12:04 AM
Why my program cannot calculate the decimal value?
pearllymary78
New To Java
4
06-23-2008
01:52 AM
Java calculator decimal
cart1443
New To Java
2
04-16-2008
02:19 PM
Capping decimal places
Rageagainst20
New To Java
1
12-20-2007
10:28 PM
round to two decimal places
javaMike
New To Java
1
11-26-2007
10:46 PM
All times are GMT +2. The time now is
12:20 AM
.
Java Tips
|
Linux Archive
Contact Us
-
Java Forums
-
Sitemap
-
Top
VBulletin, Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org
LinkBack
LinkBack URL
About LinkBacks
Bookmark & Share
Bookmark in Technorati