[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Saxon Div Issue

Subject: Re: Saxon Div Issue
From: "Michael Kay mike@xxxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Mon, 19 Jan 2015 16:19:02 -0000
Re:  Saxon Div Issue
Unless you are using schema-aware stylesheets, the result of your expression
/xpath/num when used in an arithmetic expression will first be atomized to
create an untyped atomic value, and will then be converted to an xs:double, so
the arithmetic will be done with double-precision floating-point arithmetic.
The conversion of the string "9.88" to an xs:double produces a value that is
not exactly 9.88, because decimal fractions in general cannot be exactly
represented in binary.

Michael Kay
Saxonica
mike@xxxxxxxxxxxx
+44 (0) 118 946 5893




On 19 Jan 2015, at 16:03, Mailing Lists Mail daktapaal@xxxxxxxxx
<xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote:

> THe problem is , I dont know what will come in the $num. It is an
> xpath. It comes from an XML element.
>
> SO sometimes, the element contains 988, and sometimes it contains 98.8
> .. so my pseudo code actually is :"
>
> $num = /xpath/num
> var result = $num div 100
>
> I wouldn't know if it will be a double that I will be a decimal.
>
> Dak
>
>
> On Mon, Jan 19, 2015 at 10:57 AM, G. Ken Holman g.ken.holman@xxxxxxxxx
> <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote:
>> At 2015-01-19 15:46 +0000, Mailing Lists Mail daktapaal@xxxxxxxxx wrote:
>>>
>>> I have a value 9.88 , I use the div  to do an operation
>>>
>>> Pseudo code:
>>>
>>> var num = 9.88
>>> var result = $num div 100
>>>
>>> I expect 0.0988 .. I get 0.09880000000000001
>>>
>>> I am using Saxon-EE-9.5.1-5.jar
>>>
>>> What is happening?
>>
>>
>> What is happening is that doing the arithmetic with the binary
>> representations of 9.88 and 100 create a result in binary that when
>> precisely converted to decimal give you the result you see.
>>
>> As Martin suggests, if you are using XSLT 2 then you can use decimal
>> representations of your values and do arithmetic with those.
>>
>> I hope this helps understand the issue.
>>
>> . . . . . . Ken
>>
>> --
>> Check our site for free XML, XSLT, XSL-FO and UBL developer resources |
>> Free 5-hour lecture:  http://www.CraneSoftwrights.com/links/video.htm |
>> Crane Softwrights Ltd.             http://www.CraneSoftwrights.com/s/ |
>> G. Ken Holman                    mailto:gkholman@xxxxxxxxxxxxxxxxxxxx |
>> Google+ profile:       http://plus.google.com/+GKenHolman-Crane/about |
>> Legal business disclaimers:     http://www.CraneSoftwrights.com/legal |
>>
>>
>> ---
>> This email has been checked for viruses by Avast antivirus software.
>> http://www.avast.com

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.