on 01-05-2010 10:08 PM
Hi,
I have a problem in decimal formatting in one of our application. we have a few financial figures which come in format ###.## but when both or any one of the decimal points are zero our application shows only the non zero value i.e
if the values returned but backend system is 1.22 the app shows 1.22
if the values returned is 1.00 the app shows 1 only
if the values returned is 1.20 the app shows 1.2 only
I want the decimals to be consistent as ###.## format only
Can somebody please suggest me a solution.
Edited by: Siddharth Chauhan on Jan 6, 2010 3:38 AM
Hi Siddharth,
Use this format "###.00"
Check this code also.
import java.text.DecimalFormat;
import java.text.NumberFormat;
class DecimalCheck
{
public static void main(String[] args)
{
System.out.println("Hello World!");
double amount1 = 1.22;
double amount2= 1.00;
double amount3 = 1.20;
NumberFormat formatter1 = new DecimalFormat("###.00");
NumberFormat formatter2 = new DecimalFormat("###.00");
NumberFormat formatter3 = new DecimalFormat("###.00");
System.out.println("The Decimal Value is:"+formatter1.format(amount1));
System.out.println("The Decimal Value is:"+formatter2.format(amount2));
System.out.println("The Decimal Value is:"+formatter3.format(amount3));
}
}
Regards,
Mithu
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
Pease create a simple type of type decimal.
Go to the representation tab . In that under the external representation give the required format(##0.0#)
Map this simpletype to the attribute.
Regards,
Saravanan K
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
you can also modify disply rules for context attributes at runtime, without using predefined Simple Types.
I don't have coding at hand, but this pseudo code shows how it works in principle:
wdInit() {
INode myNode = wdContext.getNode()
myAttrInfo = myNode.getAttribute("MYATTRIBUTE").getInfo()
myAttrInfo.setFormat("###.0#")
}
Hi Siddharth,
You can use java's Decimal formatter as menation in the last post.
I want the decimals to be consistent as ###.## format only:- for this at the time when u r going to define the format u need in the constructor of class Decimal formatterthe, the way u want pls defien format as ###.#0.
Hope this may help you...
Deepak!!!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Use the Java DecimalFormat class.
[http://java.sun.com/j2se/1.4.2/docs/api/java/text/DecimalFormat.html|http://java.sun.com/j2se/1.4.2/docs/api/java/text/DecimalFormat.html]
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
89 | |
10 | |
9 | |
9 | |
9 | |
6 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.