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

Re: format-number round is not desired

Subject: Re: format-number round is not desired
From: Michael Kay <mike@xxxxxxxxxxxx>
Date: Mon, 23 Apr 2012 11:06:48 +0100
Re:  format-number round is not desired
floor() adjusts towards minus infinity. It sounds like you want to adjust towards zero. A crude way to do that is to convert to a string and use substring-before($x, '.'), then convert back to a number. I would tend to prefer (for XPath 2.0)

if (abs($x) ge 0) then floor($x) else ceiling($x)

Or if it's worth implementing some functions then define

signum($x) ==> if ($x gt 0) then +1 else if ($x lt 0) then -1 else 0

and

truncate($x) ==> floor(abs($x)) * signum($x)

Michael Kay
Saxonica

On 23/04/2012 10:26, henry human wrote:
Hi guys
There is still a penalty, now If the number is negative the floor funciton rounds!
Sample:
$var = - 20624.50
output = -0000000020625
-------------------------------------
The output should be -0000000020624
?


----- Urspr|ngliche Message -----
Von: henry human<henry_human@xxxxxxxx>
An: "xsl-list@xxxxxxxxxxxxxxxxxxxxxx"<xsl-list@xxxxxxxxxxxxxxxxxxxxxx>
CC:
Gesendet: 15:09 Donnerstag, 19.April 2012
Betreff: Re: format-number round is not desired


Hi all!
That is the solution!
Thanks a lot!
Kind regards
Hen

----- Urspr|ngliche Message -----
Von: Martin Honnen<Martin.Honnen@xxxxxx>
An: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
CC:
Gesendet: 13:59 Donnerstag, 19.April 2012
Betreff: Re:  format-number round is not desired

henry human wrote:
Hello
I have following :
$var = 206000.7625
<xsl:value-of select="format-number($var ,'00000000000000;00000000000000') "/>
Output is  00000000206001
As you see the output is rounded, what is not desired!
This should be the output: 00000000206000
(the same as in  $var = 206000)
Does
   format-number(floor($var), '00000000000000;00000000000000')
do what you want?

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.