469,336 Members | 5,494 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,336 developers. It's quick & easy.

How to dispaly two decimal points in java

4
Hi,
How to dispaly two dicimal points in java (Example 1) 5.70 Example 2) 561 but it should display as 561.00)

Example1) Here I am able to display 5.7 but it should display as 5.70
Example 2) Here I am able to display 561 but it should display as 561.00

Following is the code I wrote

public MaintainOrdersAMImpl()
{
mDECIMAL_PLACES = 2;
}

public String computeMarginPercent()
{
double dTotalSellPrice = 0.0D;
double dTotalRebate = 0.0D;
double dTotalMargin = 0.0D;
GetOrderLineDetailsVORowImpl orderlineRow = null;
GetOrderLineDetailsVOImpl orderVO = (GetOrderLineDetailsVOImpl)findViewObject("GetOrde rLineDetailsVO");
orderVO.reset();
while(orderVO.hasNext())
{
orderlineRow = (GetOrderLineDetailsVORowImpl)orderVO.next();
dTotalSellPrice += orderlineRow.getExtendedSellingPrice().doubleValue ();
dTotalRebate += orderlineRow.getExtendedRebate().doubleValue();
dTotalMargin += orderlineRow.getExtendedMargin().doubleValue();
}
NumberFormat form = NumberFormat.getInstance();
form.setMaximumFractionDigits(mDECIMAL_PLACES);
return form.format((dTotalMargin * 100D) / dTotalSellPrice);
}

Please correct my code if am wrong and help me in this regard.
Thanks in advance.
Sep 17 '07 #1
9 8039
stack
40
How to dispaly two dicimal points in java (Example 1) 5.70 Example 2) 561 but it should display as 561.00)
Maybe this can help you.

import java.text.*;
public class NewClass{

public static void main (String [] args){

DecimalFormat MyFormat = new DecimalFormat(".00");
System.out.print(MyFormat.format(561));
}
}

Cheers
Sep 17 '07 #2
r035198x
13,262 8TB
Maybe this can help you.

import java.text.*;
public class NewClass{

public static void main (String [] args){

DecimalFormat MyFormat = new DecimalFormat(".00");
System.out.print(MyFormat.format(561));
}
}

Cheers
Also have a look at System.out.printf
Sep 18 '07 #3
vsraot
4
Also have a look at System.out.printf
Hi,
Thank you very much for your reply.
Your suggested code is exactly meeting the requirement then I modified the code but I faild to integrate it. Please help me .

Following is code what I wrote. (It consists of 2 files)

//Following is the File 1

package oracle.apps.ont.margin.server;

import java.text.NumberFormat;
import java.text.*;
import oracle.apps.fnd.framework.OAException;
import oracle.apps.fnd.framework.server.OAViewRowImpl;
import oracle.jbo.domain.Number;
import oracle.jbo.server.AttributeDefImpl;

public class GetOrderLineDetailsVORowImpl extends OAViewRowImpl
{

public GetOrderLineDetailsVORowImpl()
{
mDECIMAL_PLACES = 2;
}

public Number getHeaderId()
{
return (Number)getAttributeInternal(0);
}

public void setHeaderId(Number value)
{
setAttributeInternal(0, value);
}

public Number getLineId()
{
return (Number)getAttributeInternal(1);
}

public void setLineId(Number value)
{
setAttributeInternal(1, value);
}

public Number getLineTypeId()
{
return (Number)getAttributeInternal(2);
}

public void setLineTypeId(Number value)
{
setAttributeInternal(2, value);
}

public String getLineNumber()
{
return (String)getAttributeInternal(3);
}

public void setLineNumber(String value)
{
setAttributeInternal(3, value);
}

public String getOrderedItem()
{
return (String)getAttributeInternal(4);
}

public void setOrderedItem(String value)
{
setAttributeInternal(4, value);
}

public String getOrderQuantityUom()
{
return (String)getAttributeInternal(5);
}

public void setOrderQuantityUom(String value)
{
setAttributeInternal(5, value);
}

public Number getPricingQuantity()
{
return (Number)getAttributeInternal(6);
}

public void setPricingQuantity(Number value)
{
setAttributeInternal(6, value);
}

public String getPricingQuantityUom()
{
return (String)getAttributeInternal(7);
}

public void setPricingQuantityUom(String value)
{
setAttributeInternal(7, value);
}

public Number getOrderedQuantity()
{
return (Number)getAttributeInternal(8);
}

public void setOrderedQuantity(Number value)
{
setAttributeInternal(8, value);
}

public Number getUnitSellingPrice()
{
return (Number)getAttributeInternal(9);
}

public void setUnitSellingPrice(Number value)
{
setAttributeInternal(9, value);
}

public Number getUnitListPrice()
{
return (Number)getAttributeInternal(10);
}

public void setUnitListPrice(Number value)
{
setAttributeInternal(10, value);
}

public String getItemTypeCode()
{
return (String)getAttributeInternal(11);
}

public void setItemTypeCode(String value)
{
setAttributeInternal(11, value);
}

public String getLineCategoryCode()
{
return (String)getAttributeInternal(12);
}

public void setLineCategoryCode(String value)
{
setAttributeInternal(12, value);
}

public String getItemIdentifierType()
{
return (String)getAttributeInternal(13);
}

public void setItemIdentifierType(String value)
{
setAttributeInternal(13, value);
}

public Number getUnitCost()
{
return (Number)getAttributeInternal(14);
}

public void setUnitCost(Number value)
{
setAttributeInternal(14, value);
}

public Number getRebate()
{
return (Number)getAttributeInternal(15);
}

public void setRebate(Number value)
{
setAttributeInternal(15, value);
}

public Number getDiscount()
{
Number vUnitListPrice = getUnitListPrice();
if(vUnitListPrice == null)
vUnitListPrice = new Number(0);
Number vUnitSellingPrice = getUnitSellingPrice();
if(vUnitSellingPrice == null)
vUnitSellingPrice = new Number(0);
Number vRebate = getRebate();
if(vRebate == null)
vRebate = new Number(0);
double discount = (vUnitListPrice.doubleValue() - vUnitSellingPrice.doubleValue()) + vRebate.doubleValue();
if(discount < (double)0)
discount = 0.0D;
NumberFormat form = NumberFormat.getInstance();
form.setMaximumFractionDigits(mDECIMAL_PLACES);
try
{
Number number = new Number(form.parse(form.format(discount)));
return number;
}
catch(Exception e)
{
throw OAException.wrapperException(e);
}
}

public void setDiscount(Number value)
{
setAttributeInternal(16, value);
}

public Number getMargin()
{
Number vUnitSellingPrice = getUnitSellingPrice();
if(vUnitSellingPrice == null)
vUnitSellingPrice = new Number(0);
Number vRebate = getRebate();
if(vRebate == null)
vRebate = new Number(0);
Number vUnitCost = getUnitCost();
if(vUnitCost == null)
vUnitCost = new Number(0);
try
{
Number vMargin = new Number((vUnitSellingPrice.doubleValue() + vRebate.doubleValue()) - vUnitCost.doubleValue());
/*NumberFormat form = NumberFormat.getInstance();
form.setMaximumFractionDigits(mDECIMAL_PLACES);*/

DecimalFormat MyFormat = new DecimalFormat(".00");
Number number = new Number(MyFormat.parse(MyFormat.format(vMargin.doub leValue())));
return number;
}
catch(Exception e)
{
throw OAException.wrapperException(e);
}
}

public void setMargin(Number value)
{
setAttributeInternal(17, value);
}

public Number getExtendedListPrice()
{
if(getUnitListPrice() != null && getPricingQuantity() != null)
return getUnitListPrice().multiply(getPricingQuantity());
else
return new Number(0);
}

public void setExtendedListPrice(Number value)
{
setAttributeInternal(18, value);
}

public Number getExtendedDiscount()
{
if(getDiscount() != null && getPricingQuantity() != null)
return getDiscount().multiply(getPricingQuantity());
else
return new Number(0);
}

public void setExtendedDiscount(Number value)
{
setAttributeInternal(19, value);
}

public Number getExtendedRebate()
{
if(getPricingQuantity() != null && getRebate() != null)
return getPricingQuantity().multiply(getRebate());
else
return new Number(0);
}

public void setExtendedRebate(Number value)
{
setAttributeInternal(20, value);
}

public Number getExtendedSellingPrice()
{
if(getUnitSellingPrice() != null && getPricingQuantity() != null)
return getUnitSellingPrice().multiply(getPricingQuantity( ));
else
return new Number(0);
}

public void setExtendedSellingPrice(Number value)
{
setAttributeInternal(21, value);
}

public Number getExtendedCost()
{
if(getUnitCost() != null && getPricingQuantity() != null)
return getUnitCost().multiply(getPricingQuantity());
else
return new Number(0);
}

public void setExtendedCost(Number value)
{
setAttributeInternal(22, value);
}

public Number getExtendedMargin()
{
if(getPricingQuantity() != null && getTempMargin() != null)
try
{
Number vMargin = getTempMargin().multiply(getPricingQuantity());
/*NumberFormat form = NumberFormat.getInstance();
form.setMaximumFractionDigits(mDECIMAL_PLACES);*/

DecimalFormat MyFormat = new DecimalFormat(".00");
Number number = new Number(MyFormat.parse(MyFormat.format(vMargin.doub leValue())));
return number;
}
catch(Exception e)
{
throw OAException.wrapperException(e);
}
else
return new Number(0);
}

public void setExtendedMargin(Number value)
{
setAttributeInternal(23, value);
}

public Number getMarginPercent()
{
double vMarginAmount = 0.0D;
vMarginAmount = getUnitSellingPrice().doubleValue();
if(vMarginAmount == (double)0)
return new Number(100);
vMarginAmount = (getMargin().doubleValue() * (double)100) / vMarginAmount;
Number marginPercent = null;
try
{
marginPercent = new Number(vMarginAmount);
}
catch(Exception e)
{
e.printStackTrace();
}
/*NumberFormat form = NumberFormat.getInstance();
form.setMaximumFractionDigits(mDECIMAL_PLACES);*/
DecimalFormat MyFormat = new DecimalFormat(".00");

try
{
Number number = new Number(MyFormat.parse(MyFormat.format(marginPercen t.doubleValue())));
return number;
}
catch(Exception e)
{
throw OAException.wrapperException(e);
}
}

public void setMarginPercent(Number value)
{
setAttributeInternal(24, value);
}

protected Object getAttrInvokeAccessor(int index, AttributeDefImpl attrDef)
throws Exception
{
switch(index)
{
case 0: // '\0'
return getHeaderId();

case 1: // '\001'
return getLineId();

case 2: // '\002'
return getLineTypeId();

case 3: // '\003'
return getLineNumber();

case 4: // '\004'
return getOrderedItem();

case 5: // '\005'
return getOrderQuantityUom();

case 6: // '\006'
return getPricingQuantity();

case 7: // '\007'
return getPricingQuantityUom();

case 8: // '\b'
return getOrderedQuantity();

case 9: // '\t'
return getUnitSellingPrice();

case 10: // '\n'
return getUnitListPrice();

case 11: // '\013'
return getItemTypeCode();

case 12: // '\f'
return getLineCategoryCode();

case 13: // '\r'
return getItemIdentifierType();

case 14: // '\016'
return getUnitCost();

case 15: // '\017'
return getRebate();

case 16: // '\020'
return getDiscount();

case 17: // '\021'
return getMargin();

case 18: // '\022'
return getExtendedListPrice();

case 19: // '\023'
return getExtendedDiscount();

case 20: // '\024'
return getExtendedRebate();

case 21: // '\025'
return getExtendedSellingPrice();

case 22: // '\026'
return getExtendedCost();

case 23: // '\027'
return getExtendedMargin();

case 24: // '\030'
return getMarginPercent();

case 25: // '\031'
return getExtendedMarginPercent();

case 26: // '\032'
return getTempMargin();
}
return super.getAttrInvokeAccessor(index, attrDef);
}

protected void setAttrInvokeAccessor(int index, Object value, AttributeDefImpl attrDef)
throws Exception
{
switch(index)
{
case 0: // '\0'
setHeaderId((Number)value);
return;

case 1: // '\001'
setLineId((Number)value);
return;

case 2: // '\002'
setLineTypeId((Number)value);
return;

case 3: // '\003'
setLineNumber((String)value);
return;

case 4: // '\004'
setOrderedItem((String)value);
return;

case 5: // '\005'
setOrderQuantityUom((String)value);
return;

case 6: // '\006'
setPricingQuantity((Number)value);
return;

case 7: // '\007'
setPricingQuantityUom((String)value);
return;

case 8: // '\b'
setOrderedQuantity((Number)value);
return;

case 9: // '\t'
setUnitSellingPrice((Number)value);
return;

case 10: // '\n'
setUnitListPrice((Number)value);
return;

case 11: // '\013'
setItemTypeCode((String)value);
return;

case 12: // '\f'
setLineCategoryCode((String)value);
return;

case 13: // '\r'
setItemIdentifierType((String)value);
return;

case 14: // '\016'
setUnitCost((Number)value);
return;

case 15: // '\017'
setRebate((Number)value);
return;

case 16: // '\020'
setDiscount((Number)value);
return;

case 17: // '\021'
setMargin((Number)value);
return;

case 18: // '\022'
setExtendedListPrice((Number)value);
return;

case 19: // '\023'
setExtendedDiscount((Number)value);
return;

case 20: // '\024'
setExtendedRebate((Number)value);
return;

case 21: // '\025'
setExtendedSellingPrice((Number)value);
return;

case 22: // '\026'
setExtendedCost((Number)value);
return;

case 23: // '\027'
setExtendedMargin((Number)value);
return;

case 24: // '\030'
setMarginPercent((Number)value);
return;

case 25: // '\031'
setExtendedMarginPercent((Number)value);
return;

case 26: // '\032'
setTempMargin((Number)value);
return;
}
super.setAttrInvokeAccessor(index, value, attrDef);
}

public Number getExtendedMarginPercent()
{
double vMarginAmount = 0.0D;
Number vUnitSellingPrice = getUnitSellingPrice();
if(vUnitSellingPrice == null)
vUnitSellingPrice = new Number(0);
Number vRebate = getRebate();
if(vRebate == null)
vRebate = new Number(0);
vMarginAmount = vUnitSellingPrice.doubleValue() + vRebate.doubleValue();
if(vMarginAmount == (double)0)
return new Number(100);
Number vMargin = getMargin();
if(vMargin == null)
vMargin = new Number(0);
vMarginAmount = (vMargin.doubleValue() * (double)100) / vMarginAmount;
Number marginPercent = null;
try
{
marginPercent = new Number(vMarginAmount);
}
catch(Exception e)
{
e.printStackTrace();
}
/*NumberFormat form = NumberFormat.getInstance();
form.setMaximumFractionDigits(mDECIMAL_PLACES);*/
DecimalFormat MyFormat = new DecimalFormat(".00");
try
{
Number number = new Number(MyFormat.parse(MyFormat.format(marginPercen t.doubleValue())));
return number;
}
catch(Exception e)
{
throw OAException.wrapperException(e);
}
}

public void setExtendedMarginPercent(Number value)
{
setAttributeInternal(25, value);
}

public Number getTempMargin()
{
Number vUnitSellingPrice = getUnitSellingPrice();
if(vUnitSellingPrice == null)
vUnitSellingPrice = new Number(0);
Number vRebate = getRebate();
if(vRebate == null)
vRebate = new Number(0);
Number vUnitCost = getUnitCost();
if(vUnitCost == null)
vUnitCost = new Number(0);
try
{
Number vTempMargin = new Number((vUnitSellingPrice.doubleValue() + vRebate.doubleValue()) - vUnitCost.doubleValue());
Number number = vTempMargin;
return number;
}
catch(Exception e)
{
throw OAException.wrapperException(e);
}
}

public void setTempMargin(Number value)
{
setAttributeInternal(26, value);
}

protected static final int HEADERID = 0;
protected static final int LINEID = 1;
protected static final int LINETYPEID = 2;
protected static final int LINENUMBER = 3;
protected static final int ORDEREDITEM = 4;
protected static final int ORDERQUANTITYUOM = 5;
protected static final int PRICINGQUANTITY = 6;
protected static final int PRICINGQUANTITYUOM = 7;
protected static final int ORDEREDQUANTITY = 8;
protected static final int UNITSELLINGPRICE = 9;
protected static final int UNITLISTPRICE = 10;
protected static final int ITEMTYPECODE = 11;
protected static final int LINECATEGORYCODE = 12;
protected static final int ITEMIDENTIFIERTYPE = 13;
protected static final int UNITCOST = 14;
protected static final int REBATE = 15;
protected static final int DISCOUNT = 16;
protected static final int MARGIN = 17;
protected static final int EXTENDEDLISTPRICE = 18;
protected static final int EXTENDEDDISCOUNT = 19;
protected static final int EXTENDEDREBATE = 20;
protected static final int EXTENDEDSELLINGPRICE = 21;
protected static final int EXTENDEDCOST = 22;
protected static final int EXTENDEDMARGIN = 23;
protected static final int MARGINPERCENT = 24;
protected static final int EXTENDEDMARGINPERCENT = 25;
protected static final int TEMPMARGIN = 26;
int mDECIMAL_PLACES;
}



// Following is the main file. File 2 ------------------



package oracle.apps.ont.margin.server;

import java.text.NumberFormat;
import java.text.*;
import oracle.apps.fnd.framework.server.OAApplicationModu leImpl;
import oracle.jbo.ViewLink;
import oracle.jbo.domain.Number;
import oracle.jbo.server.ApplicationModuleImpl;
import oracle.jbo.server.ViewLinkImpl;

// Referenced classes of package oracle.apps.ont.margin.server:
// GetOrderLineDetailsVOImpl, GetOrderLineDetailsVORowImpl, GetOrderHeadersVOImpl

public class MaintainOrdersAMImpl extends OAApplicationModuleImpl
{

public MaintainOrdersAMImpl()
{
mDECIMAL_PLACES = 2;
}

public String computeMarginPercent()
{
double dTotalSellPrice = 0.0D;
double dTotalRebate = 0.0D;
double dTotalMargin = 0.0D;
GetOrderLineDetailsVORowImpl orderlineRow = null;
GetOrderLineDetailsVOImpl orderVO = (GetOrderLineDetailsVOImpl)findViewObject("GetOrde rLineDetailsVO");
orderVO.reset();
while(orderVO.hasNext())
{
orderlineRow = (GetOrderLineDetailsVORowImpl)orderVO.next();
dTotalSellPrice += orderlineRow.getExtendedSellingPrice().doubleValue ();
dTotalRebate += orderlineRow.getExtendedRebate().doubleValue();
dTotalMargin += orderlineRow.getExtendedMargin().doubleValue();
}
/*NumberFormat form = NumberFormat.getInstance();
form.setMaximumFractionDigits(mDECIMAL_PLACES);*/

DecimalFormat MyFormat = new DecimalFormat(".00");
return MyFormat.format((dTotalMargin * 100D) / dTotalSellPrice);
}

public void getContextInfo(String pHeaderId)
{
GetOrderHeadersVOImpl orderVO = (GetOrderHeadersVOImpl)findViewObject("GetOrderHea dersVO");
if(orderVO != null)
try
{
Number numHeaderId = new Number(pHeaderId);
orderVO.initQuery(numHeaderId);
orderVO.reset();
orderVO.next();
oracle.jbo.Row ro = orderVO.getCurrentRow();
if(ro != null)
{
GetOrderLineDetailsVOImpl linesVO = (GetOrderLineDetailsVOImpl)findViewLink("HeaderToL inesVL1").getDestination();
if(linesVO != null)
linesVO.first();
}
}
catch(Exception exception) { }
}

public GetOrderHeadersVOImpl getGetOrderHeadersVO()
{
return (GetOrderHeadersVOImpl)findViewObject("GetOrderHea dersVO");
}

public GetOrderLineDetailsVOImpl getGetOrderLineDetailsVO()
{
return (GetOrderLineDetailsVOImpl)findViewObject("GetOrde rLineDetailsVO");
}

public ViewLinkImpl getHeaderToLinesVL1()
{
return (ViewLinkImpl)findViewLink("HeaderToLinesVL1");
}

public static void main(String args[])
{
ApplicationModuleImpl.launchTester("oracle.apps.on t.margin.server", "MaintainOrdersAMLocal");
}

int mDECIMAL_PLACES;
}

Please help me in this regard.
Thanks in advance.
Sep 25 '07 #4
stack
40
Also have a look at System.out.printf
Thanks a lot! I learn so many things here!

stack
Sep 25 '07 #5
r035198x
13,262 8TB
Please do not dump all your code here like this. It is not necessary. Just point out the part you are stuck with.
Sep 26 '07 #6
vsraot
4
Please do not dump all your code here like this. It is not necessary. Just point out the part you are stuck with.
My sincere apology for happend thing, but I thought it would be better for understanding the problem.
Sep 26 '07 #7
r035198x
13,262 8TB
My sincere apology for happend thing, but I thought it would be better for understanding the problem.
Is it working now?
Sep 26 '07 #8
vsraot
4
Is it working now?
No, it is not working.
Sep 26 '07 #9
JosAH
11,448 Expert 8TB
No, it is not working.
Read reply #2 again and also the System.out.printf() method can do the job for you.

kind regards,

Jos
Sep 26 '07 #10

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

4 posts views Thread by Enno Middelberg | last post: by
7 posts views Thread by hana1 | last post: by
8 posts views Thread by Quinn Kirsch | last post: by
15 posts views Thread by Kay Schluehr | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by Marylou17 | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.