sbutt Posted September 22, 2011 Share Posted September 22, 2011 Hi Folks, I am using XSLT 1.0, and stuck in a situation where I am having decimal rounding problem. Let me give you an example: My generated XML is: <?xml version="1.0" encoding="UTF-8"?><CostSummary><CostingItems> <CostingItem CostBasis="7" Description="Per Person" PassengerRPH="1"> <UnitCost Amount="3.333333" CurrencyCode="EUR"/> </CostingItem> <CostingItem CostBasis="7" Description="Per Person" PassengerRPH="2"> <UnitCost Amount="3.333333" CurrencyCode="EUR"/> </CostingItem> <CostingItem CostBasis="7" Description="Per Person" PassengerRPH="2"> <UnitCost Amount="3.333333" CurrencyCode="EUR"/> </CostingItem></CostingItems><GrossAmount Amount="10.00" CurrencyCode="EUR"/></CostSummary> My requirement is that the GrossAmount (10), should always be equal to the sum of all the UnitCost Amounts. In the above xml, each UnitCost Amount is generated by GrossAmount/No. of CostingItem >> 10/3= 3.33333. Hence in order to resolve this problem, I have decided to roundup the values to 2 decimal places and adjust the difference in the last CostingItem's UnitCost. For example: <?xml version="1.0" encoding="UTF-8"?><CostSummary><CostingItems> <CostingItem CostBasis="7" Description="Per Person" PassengerRPH="1"> <UnitCost Amount="3.34" CurrencyCode="EUR"/> </CostingItem> <CostingItem CostBasis="7" Description="Per Person" PassengerRPH="2"> <UnitCost Amount="3.34" CurrencyCode="EUR"/> </CostingItem> <CostingItem CostBasis="7" Description="Per Person" PassengerRPH="2"> <UnitCost Amount="3.32" CurrencyCode="EUR"/> </CostingItem></CostingItems><GrossAmount Amount="10.00" CurrencyCode="EUR"/></CostSummary> So could someone please help me out in creating the xslt script for the above scenario? I am currently using xslt 1.0. Thanks. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.