Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "changing the decimal format representation" Watch "changing the decimal format representation" New topic
Author

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.


Thanks,

Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14074
    
  16

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 7 API documentation
Scala Notes - My blog about Scala
 
wood burning stoves
 
subject: changing the decimal format representation
 
Similar Threads
Correctly specified Identifiers
why the long value print 10 ,not 12 ?
Decimals not converting to correct fractions
Urgent A method in Java which rounds 18 places to 8 places after decimal
How to find number of decimal places?