Results 1 to 6 of 6
- 03-24-2011, 08:52 AM #1
Senior Member
- Join Date
- Feb 2011
- Posts
- 107
- Rep Power
- 0
keep double accurate to two decimal places
Hie guys I have a double variable that holds product costs after multiplying cost per kg with the actual weight selected. How do I keep the numbers accurate to just two decimal places. I don't want numbers like $2.555555578, instead I need $2.55. Please help.
- 03-24-2011, 09:34 AM #2
Use BigDecimal. Or if it's just the display of the numbers that's bothering you, DecimalFormat.
db
- 03-24-2011, 11:13 AM #3
Senior Member
- Join Date
- Feb 2011
- Posts
- 107
- Rep Power
- 0
Thanks for that, Decimal Format did it. Some rep for you :D
- 03-24-2011, 05:23 PM #4
Senior Member
- Join Date
- Nov 2010
- Posts
- 210
- Rep Power
- 3
Alternatively, you might want to consider using an int and keeping track of the amount in cents instead of dollars.
- 03-24-2011, 05:27 PM #5
Senior Member
- Join Date
- Feb 2011
- Posts
- 107
- Rep Power
- 0
@Iron Lion
That is really clever. I had actually never thought of that.
In real world application how is it done?
- 03-24-2011, 06:23 PM #6
Similar Threads
-
3 Decimal Places
By benhawk in forum New To JavaReplies: 7Last Post: 11-02-2010, 09:28 PM -
Limiting decimal places in a double
By darek9576 in forum New To JavaReplies: 5Last Post: 03-14-2010, 01:13 AM -
rounding double to two decimal places
By javaMike in forum Advanced JavaReplies: 15Last Post: 03-10-2010, 12:04 AM -
How to display an int or a double with two decimal places
By mcollins in forum New To JavaReplies: 4Last Post: 03-03-2009, 12:43 PM -
numbers with two decimal places
By little_polarbear in forum New To JavaReplies: 8Last Post: 08-27-2008, 11:04 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks