Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xslt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/amazon-s3/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
XSLT2.0如何对数字进行舍入?1.45632=>;1.46_Xslt_Xslt 2.0 - Fatal编程技术网

XSLT2.0如何对数字进行舍入?1.45632=>;1.46

XSLT2.0如何对数字进行舍入?1.45632=>;1.46,xslt,xslt-2.0,Xslt,Xslt 2.0,如何在XSLT2.0中对数字进行舍入 例如,它的工作原理如下: 1.4367 => 1.44 1.3218 => 1.32 <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" exclude

如何在XSLT2.0中对数字进行舍入

例如,它的工作原理如下:

1.4367 => 1.44
1.3218 => 1.32
<xsl:stylesheet version="2.0"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:xs="http://www.w3.org/2001/XMLSchema"
                exclude-result-prefixes="xs">
  <xsl:output omit-xml-declaration="yes" indent="yes"/>
  <xsl:strip-space elements="*"/>

  <xsl:template match="/*">
    <MyTable>
      <xsl:value-of select="xs:decimal(MyValue)"/>
    </MyTable>
  </xsl:template>
</xsl:stylesheet>

您可能正在寻找函数

同样,在XSLT2.0/XPath2.0中,可以使用
xs:decimal
类型在不损失精度的情况下工作

大概是这样的:

1.4367 => 1.44
1.3218 => 1.32
<xsl:stylesheet version="2.0"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:xs="http://www.w3.org/2001/XMLSchema"
                exclude-result-prefixes="xs">
  <xsl:output omit-xml-declaration="yes" indent="yes"/>
  <xsl:strip-space elements="*"/>

  <xsl:template match="/*">
    <MyTable>
      <xsl:value-of select="xs:decimal(MyValue)"/>
    </MyTable>
  </xsl:template>
</xsl:stylesheet>

尝试使用舍入功能:

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

您可能还想看看round-half-to-even(),它执行“银行家四舍五入”,并允许您指定小数位数。