DecimalFormat « decimal « Java Data Type Q&A

Home
Java Data Type Q&A
1.bigdecimal
2.biginteger
3.bit
4.Boolean
5.byte
6.Calendar
7.cast
8.character
9.Date Time
10.Date Time Format
11.decimal
12.Development
13.double
14.enum
15.float
16.hexadecimal
17.Integer
18.Number
19.Number Format
20.primitive
21.SimpleDateFormat
22.string
23.StringBuffer
24.StringBuilder
25.StringTokenizer
26.substring
27.TimeZone
Java Data Type Q&A » decimal » DecimalFormat 

1. How to always show decimal part when using DecimalFormat?    stackoverflow.com

Float sum = new Float(300); // always somehow calculated
DecimalFormat df = new DecimalFormat("#.#");
String s = df.format(sum/3);  // prints 100, I want 100.0
s = df.format(301/3); // pritns 100.3 which is correct
Result ...

2. DecimalFormat drops the 0s after decimal point. I need to keep them.    coderanch.com

Hi, I have to show the number as is without dropping the end 0s after decimal. e.g. I need to show 12 as 12, 13.0 as 13.0 14.50 as 14.50. But the decimal format removes the last zero. Unfortunately, JFreeChart tooltip logic requires a decimal format to be specified to do anything like this. Any idea how we can achieve this. ...

java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.