ASG
IBM
Zystems
Cressida
Icon
Netflexity
 
  MQSeries.net
Search  Search       Tech Exchange      Education      Certifications      Library      Info Center      SupportPacs      LinkedIn  Search  Search                                                                   FAQ  FAQ   Usergroups  Usergroups
 
Register  ::  Log in Log in to check your private messages
 
RSS Feed - WebSphere MQ Support RSS Feed - Message Broker Support

MQSeries.net Forum Index » WebSphere Message Broker (ACE) Support » Data Map (or Mapping Node) and fractional digits

Post new topic  Reply to topic
 Data Map (or Mapping Node) and fractional digits « View previous topic :: View next topic » 
Author Message
Gideon
PostPosted: Wed Jan 21, 2015 11:54 am    Post subject: Data Map (or Mapping Node) and fractional digits Reply with quote

Chevalier

Joined: 18 Aug 2009
Posts: 403

I am using IIB 9.0.0.2

I am using the Data Map (similar to Mapping node) to convert two different structures

I am using XQuery generation, and my output format is as follows:

Code:
  <xs:simpleType name="Money">
    <xs:restriction base="xs:decimal">
         <xs:fractionDigits value="2"/>
     </xs:restriction>
  </xs:simpleType>


I perform a summation in XQuery, but I get the following output:

Code:
36745.770000000004


How can I tell the tool to only give me two fractional digits ?
Back to top
View user's profile Send private message Send e-mail
martinb
PostPosted: Wed Jan 21, 2015 11:52 pm    Post subject: Reply with quote

Master

Joined: 09 Nov 2006
Posts: 210
Location: UK

What you really want is for the Mapping node / Data Map to provide the XQuery/XPath 3.0 functions, that you could simply use "format-number".

Although you've only said you are using the Data Map to generate the XQuery from the Graphical Map, not where you are executing, so if you have a runtime that supports XQuery/XPath 3.0, go that way.

Otherwise if you execution runtime is XQuery 2.0, your options are to either call out to say Java and do the formatting there, or the following is one way to achieve this using XQuery/XPath 2.0 functions
Code:

let $sum :=  xs:string(fn:sum($nums)) return
let $whole := fn:substring-before( $sum,  '.') return
let $fac := fn:substring-after(  $sum,  '.') return
fn:concat( $whole, '.', fn:substring($fac,1,2) )

The above can be used in a Custom XPath transform in a Graphical Data Map, assuming "$nums" is the variable name given by content assist for a repeating set of decimal numbers
Back to top
View user's profile Send private message
martinb
PostPosted: Thu Jan 22, 2015 8:37 am    Post subject: Reply with quote

Master

Joined: 09 Nov 2006
Posts: 210
Location: UK

A far simpler solution, and more robust to my first response, is to use an XQuery 2 function I'd initially forgotten allows a precision parameter

fn:round-half-to-even( fn:sum($nums), 2)
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic  Reply to topic Page 1 of 1

MQSeries.net Forum Index » WebSphere Message Broker (ACE) Support » Data Map (or Mapping Node) and fractional digits
Jump to:  



You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Protected by Anti-Spam ACP
 
 


Theme by Dustin Baccetti
Powered by phpBB © 2001, 2002 phpBB Group

Copyright © MQSeries.net. All rights reserved.