Click here to Skip to main content
15,887,485 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hi all,

I'm trying to format a report which accepts amounts, the following works just fine:

<xsl:value-of select="format-number(@Amount, " xmlns:xsl="#unknown"></xsl:value-of>


But how do I get it to display an apostrophe for a thousand separator, as they like it here in Switzeerland?

Using
<xsl:value-of select="format-number(@Amount, "###" hold=" /><br mode=" xmlns:xsl="#unknown"></xsl:value-of>
Posted
Updated 13-Jul-11 5:51am
v3

Hi,

Use xsl:decimal-format, there is an article about that on MSDN.

http://msdn.microsoft.com/en-us/library/ms256225.aspx[^]

For example this is the german format:

XML
<xsl:decimal-format name="european" decimal-separator=',' grouping-separator='.' />
<xsl:value-of select="format-number(24535.2, '###.###,00', 'european')"/>


You just need to re-work this a bit to make it swiss friendly.

Valery.
 
Share this answer
 
Found difficulty with this - the apostrophe character is not supported.

Ended up doing a format in SQL code to output the formatted mount alongside the raw amount, then an XSL variable to select the class of the span. Messy.

If anyone is interested here is the SQL format function, could be useful. As you can see, it's quite a specific format....

****** Object:  UserDefinedFunction [Intern].[fFormatNumberAsString]    Script Date: 07/14/2011 10:31:29 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[Intern].[fFormatNumberAsString]') AND type in (N'FN', N'IF', N'TF', N'FS', N'FT'))
DROP FUNCTION [Intern].[fFormatNumberAsString]
GO
/*
	Author	:	Mel Padden	
	Purpose :	Formatting of floats as strings without scientific notation for XML resultsets

*/
CREATE FUNCTION [Intern].[fFormatNumberAsString](
	@RawNumber			FLOAT		= 0
,	@NumberOfDecimals	INT			= 2
,	@ThousandDelim		NVARCHAR(1) = ''''
,	@DecimalDelim		NVARCHAR(1) = '.'
)
RETURNS NVARCHAR(MAX) AS
BEGIN
    DECLARE @FormattedNumber	AS VARCHAR(100);
    DECLARE @AfterDecimal		AS VARCHAR(100);
    DECLARE @Negative			AS BIT;
	IF		@RawNumber < 0 SET @Negative = 1;
	ELSE	SET @Negative = 0;
    SET @FormattedNumber = CONVERT(BIGINT, ABS(@RawNumber));
	
	IF @NumberOfDecimals = 0 BEGIN
		SET @AfterDecimal = '';
	END ELSE BEGIN
		/*	Subtract the integer part from the float to get the decimal remainder */
		SET @AfterDecimal = ROUND((FLOOR(@RawNumber) - @RawNumber), @NumberOfDecimals);
		IF CHARINDEX('.', @AfterDecimal) <> 0 BEGIN
			SET @AfterDecimal = @DecimalDelim + RIGHT(@AfterDecimal, LEN(@AfterDecimal) - CHARINDEX('.',	@AfterDecimal));
		END ELSE BEGIN
			SET @AfterDecimal = '';
		END
	END
	    
	DECLARE @i AS INT;
    DECLARE @j AS INT;
    SET @i = 0;
    SET @j = 0;
    WHILE @i <> LEN(@FormattedNumber) BEGIN
        IF @j = 3 BEGIN
            SET @j = - 1;
            SET @FormattedNumber = LEFT(@FormattedNumber, LEN(@FormattedNumber) - @i) + @ThousandDelim + RIGHT(@FormattedNumber, @i);
        END
        SET @j = @j + 1;
        SET @i = @i + 1;
    END
    SET @FormattedNumber =  @FormattedNumber + @AfterDecimal;
	IF @Negative = 1 SET @FormattedNumber = '(' + @FormattedNumber + ')-';
    RETURN @FormattedNumber
END
GO
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900