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
Win a copy of
video training course 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 8 API documentation
I agree. Here's the link:
subject: changing the decimal format representation
Urgent A method in Java which rounds 18 places to 8 places after decimal
Decimals not converting to correct fractions
why the long value print 10 ,not 12 ?
Correctly specified Identifiers
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-2015