Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
A friendly place for programming greenhorns!
Big Moose Saloon
Register / Login
Win a copy of
Murach's Java Servlets and JSP
this week in the
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
subject: changing the decimal format representation
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?
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter
| Powered by
Copyright © 1998-2014