使用分隔符时的 XML 格式数字问题

发布于 2024-07-13 10:00:05 字数 980 浏览 5 评论 0原文

我们正在开发一个网页,该网页应该能够显示价格,其中空格是分组分隔符,逗号是小数点分隔符。 例如,值 1234567.89 应显示为 1 234 567,89。 (我们实际上使用的是  ,因此我们得到了一个不间断的空格。)

这似乎是正确的 XSL,而且它几乎可以工作,但我得到了一个“.”。 其余部分之后的字符。 所以我最终得到 “1 234 567,89。” 代替 “1 234 567,89”

<?xml version='1.0' encoding='iso-8859-1'?>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fo="http://www.w3.org/1999/XSL/Format"
xmlns:msxsl="urn:schemas-microsoft-com:xslt" 
xmlns:hsi="http://www.myfakecompany.com/fakey" 
extension-element-prefixes="msxsl hsi">

    <xsl:decimal-format name="euro" 
        decimal-separator="," 
        grouping-separator="&#160;"/>

    <xsl:template match="/">

    <xsl:value-of select="format-number(1234567.89, '#&#160;###.##;(#&#160;###.##)', 'euro')"/>

    </xsl:template>
</xsl:stylesheet>

有任何想法吗?

We're working on a web page that should be able to display prices such that spaces are the grouping separators and commas are the decimal separators. For example, the value 1234567.89 should display as 1 234 567,89. (We're actually using   so we get a non-breaking space.)

This seems like the right XSL to do it, and it almost works, but I get a "." character after the rest of it. So I end up with
"1 234 567,89."
instead of
"1 234 567,89".

<?xml version='1.0' encoding='iso-8859-1'?>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fo="http://www.w3.org/1999/XSL/Format"
xmlns:msxsl="urn:schemas-microsoft-com:xslt" 
xmlns:hsi="http://www.myfakecompany.com/fakey" 
extension-element-prefixes="msxsl hsi">

    <xsl:decimal-format name="euro" 
        decimal-separator="," 
        grouping-separator=" "/>

    <xsl:template match="/">

    <xsl:value-of select="format-number(1234567.89, '# ###.##;(# ###.##)', 'euro')"/>

    </xsl:template>
</xsl:stylesheet>

Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

会傲 2024-07-20 10:00:05

格式字符串在设置小数分隔符后应用,因此您需要将其更改为:

'# ###,##;(# ###,##)'

即用逗号而不是句点。

The format string is applied after the decimal separator is set, so you need to change it to:

'# ###,##;(# ###,##)'

I.e. with commas instead of periods.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文