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

Re: Truncate input

Subject: Re: Truncate input
From: Abel Braaksma <abel.online@xxxxxxxxx>
Date: Mon, 11 Sep 2006 16:56:22 +0200
xsl truncate
Hi M Core,

Not sure if your question is about XSLT or XSL, since there's no mention of either in your post.

If you want to format a number, you can use <xsl:decimal-format /> with format-number(value, format, name). The name in format-number refers to a name you predefined with <xsl:decimal-format />. Recall that <xsl:decimal-number /> is a top-level element. This means it must be right under your <xsl:stylesheet> instruction.

You may also choose to format your number using the <xsl:number /> instruction or using string concatenation functions.

If you need rounding, you can use the round(number) xpath function, but since you say that 3,45678 must become 3,45, I guess you need truncating. If you use round(), be aware that it only returns integers.

-- using <xsl:number />
<xsl:number value="$yourinput" format="1.00" />

-- using round()
<xsl:value-of select="round($yourinput * 100) div 100" />

-- using fixed() (will truncate)
<xsl:value-of select="fixed($yourinput * 100) div 100" />

-- using string functions:
<xsl:value-of select="concat ( substring-before( $yourinput, '.' ) , '.' , substring ( substring-after ( $yourinput, '.' ) , 1 , 2 ) )" />


You may have noticed that all these functions take input as a number that has a dot for decimal. You use a comma for decimal, so you may need to convert it. The easy thing to do that is using translate(string, tr, repl), I think:

-- converting your number:
<xsl:value-of select="translate ( $yournumber , ',' , '.' )" />

All the above snippets work with XSLT 1.0. But you can use them with 2.0 if you like or need it. There are many more possibilities.

Cheers,
Abel Braaksma
http://abelleba.metacarpus.com


m.core@xxxxxxxxxxxxxxxx wrote:
Hi all,

i need to truncate input that can be write in a box i have a var v1=2 if after coma there is more then v1 numbers then it must be truncate to v1 es...

if i insert 3,45678 in the input it let me write only 3,45 because v1=2

i think this must be done in the tags <input > </input>
i'm already in the case that the number is real ecc..

How can i do?..is there an option like <input format="">?

thx for replies

Current Thread
  • Truncate input
    • m.core - 11 Sep 2006 09:17:57 -0000
      • Steve - 11 Sep 2006 10:40:28 -0000
      • Abel Braaksma - 11 Sep 2006 14:56:38 -0000 <=

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.