Need help with Java( on the double )
Need help with Java( on the double )
Anyone, plz help me asap
how do I round off to two decimal places in java(the datatype is double).
I tried using DecimalFormat but i get errors.
i am stuck because of this
please help
how do I round off to two decimal places in java(the datatype is double).
I tried using DecimalFormat but i get errors.
i am stuck because of this
please help
Running Vista is like being in a candy store that only sells black liquorice at exorbitant prices. Oh, and you\'re only allowed to eat the candy in the store.
-
- Moderator Emeritus
- Posts: 6866
- Joined: 12 Dec 2003, 02:00
- Location: JHB
- Contact:
-
- Registered User
- Posts: 20576
- Joined: 19 Sep 2003, 02:00
- Location: Bloodbank
Take note that the print and printf functions are only available in JDK5. The formatting within these two methods occurs exactly the same as in c's cprintf and cprint methods.
Anyway I would be more interested in seing the code that causes your problem and then trying to correct that than giving you a couple of examples.
Anyway I would be more interested in seing the code that causes your problem and then trying to correct that than giving you a couple of examples.
- Spoiler (show)
- rustypup
- Registered User
- Posts: 8872
- Joined: 13 Dec 2004, 02:00
- Location: nullus pixius demonica
- Contact:
Agreed....RuadRauFlessa wrote:Anyway I would be more interested in seing the code that causes your problem and then trying to correct that than giving you a couple of examples.
Problem : The alg used to handle rounding for doubles is prone to NaN or Infinity on certain cpu's.... ignore this at your own peril. You can check for these using the static methods Double.isNaN(dble) or Double.isInfinity(dble)....
Consider using BigDecimal or BigInteger in double precision ops....
-
- Registered User
- Posts: 20576
- Joined: 19 Sep 2003, 02:00
- Location: Bloodbank
Ello Rustypup. I weould like to welome you to the forums on behalf of all the moderators over here. Hope you have a plesent stay mate
- Spoiler (show)
-
- Registered User
- Posts: 20576
- Joined: 19 Sep 2003, 02:00
- Location: Bloodbank
We are all mates here, We laugth,play and shout together. Keep the source flowing man I gotta get back to work.
- Spoiler (show)