File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
A friendly place for programming greenhorns!
Big Moose Saloon
Register / Login
Java in General
changing the decimal format representation
Joined: Nov 29, 2004
Apr 27, 2011 07:26:18
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
Joined: Aug 16, 2005
Apr 27, 2011 07:45:25
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
, or by using System.out.printf():
double number = .05; System.out.printf("The number is: %.2f%n", number + 1.0);
Java Beginners FAQ
JavaRanch SCJP FAQ
The Java Tutorial
Java SE 7 API documentation
- My blog about Scala
With a little knowledge, a
cast iron skillet
is non-stick and lasts a lifetime.
subject: changing the decimal format representation
Correctly specified Identifiers
Urgent A method in Java which rounds 18 places to 8 places after decimal
why the long value print 10 ,not 12 ?
How to find number of decimal places?
Decimals not converting to correct fractions
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter
| Powered by
Copyright © 1998-2014