File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes changing the decimal format representation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "changing the decimal format representation" Watch "changing the decimal format representation" New topic

changing the decimal format representation

Mohit Sinha
Ranch Hand

Joined: Nov 29, 2004
Posts: 125
Hi there,

I have a requirement wherein I need to change the way decimal place values are displayed

Currently my calculation yields double value .05 or -.03 which i want to represent something like this 1.05 or .97 respectively.

Let me know the best approach.


Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 15081

Do you just want to print the number plus one? Then just add 1 to the number before displaying it.

Or is your question about actually formatting numbers? There are several ways to do that; for example using class java.text.DecimalFormat, or by using System.out.printf():

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
I agree. Here's the link:
subject: changing the decimal format representation
It's not a secret anymore!