Results 1 to 4 of 4
Thread: round to two decimal places
- 11-26-2007, 04:49 PM #1
Member
- Join Date
- Nov 2007
- Posts
- 5
- Rep Power
- 0
- 11-26-2007, 09:46 PM #2
Java Code:double[] d = { 1.0/3.0, Math.PI, 2.0/3.0 }; for(int j = 0; j < d.length; j++) { System.out.printf("d[%d] = %f%n", j, d[j]); double d2 = (int)Math.round(d[j] * 100)/100.0; System.out.printf("d2 = %f%n", d2); }
- 12-23-2011, 02:46 PM #3
Member
- Join Date
- Dec 2011
- Posts
- 1
- Rep Power
- 0
Re: round to two decimal places
Simple solution:
(Math.round(d*100))/100Last edited by HansW; 12-23-2011 at 03:30 PM.
- 12-24-2011, 02:01 AM #4
Re: round to two decimal places
Wrong. Not a solution at all.
What Every Computer Scientist Should Know About Floating-Point Arithmetic
And since this thread is over 4 years old, I'm closing it. If you have any questions, please start your own thread.
dbWhy do they call it rush hour when nothing moves? - Robin Williams
Similar Threads
-
rounding double to two decimal places
By javaMike in forum Advanced JavaReplies: 15Last Post: 03-10-2010, 12:04 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 -
Converts a binary number to a decimal
By cachi in forum New To JavaReplies: 1Last Post: 08-01-2007, 09:57 AM -
How to round a double?
By Valeriano in forum New To JavaReplies: 1Last Post: 05-31-2007, 03:50 PM


1Likes
LinkBack URL
About LinkBacks


Bookmarks