整分钟附近的秒数似乎转换不正确
Seconds to Time near the full minute appears to convert incorrectly
我 运行 遇到了一个我不确定如何解决的问题。我使用 Seconds to Time 中的答案在 XSLT 1.0 中创建了一个模板。但是,当我的持续时间接近整数时,结果不正确。当 运行 的值比这个大得多或小得多时,结果似乎是正确的。
我的模板如下。当我的持续时间为 3597 时,结果出现在 00:60:57 而不是 00:59:57 并且持续时间 955 给出了 00:16:55 而不是 00:15:55.[=12= 的结果]
我曾尝试删除模数,以为我可以只对结果进行子字符串化,但这并没有改变 3597 结果,并且弄乱了在下面的代码下正确的多个结果。我还扩展了格式编号以包含更多数字,但这也不会改变结果。我也尝试过使用 floor($Duration - $hours div 60),但似乎没有用,或者我的格式不对。
我错过了什么?我看不出 3597/60 怎么等于 60,尤其是当我取模数时。
<xsl:template name="calculatedDuration">
<xsl:param name="Duration"/>
<xsl:choose>
<xsl:when test="$Duration >= 3600">
<xsl:value-of select="concat(format-number($Duration div 3600, '00'), ':')"/>
</xsl:when>
<xsl:otherwise>00:</xsl:otherwise>
</xsl:choose>
<xsl:value-of select="format-number($Duration div 60 mod 60, '00')"/>
<xsl:value-of select="concat(':', format-number($Duration mod 60, '00'))"/>
</xsl:template>
这是因为 format-number
进行舍入,而不是截断。 format-number(59.97, '00')
的值为 60,而不是 59。因此请改用 format-number(floor($Duration div 60) mod 60, '00')
。
我 运行 遇到了一个我不确定如何解决的问题。我使用 Seconds to Time 中的答案在 XSLT 1.0 中创建了一个模板。但是,当我的持续时间接近整数时,结果不正确。当 运行 的值比这个大得多或小得多时,结果似乎是正确的。
我的模板如下。当我的持续时间为 3597 时,结果出现在 00:60:57 而不是 00:59:57 并且持续时间 955 给出了 00:16:55 而不是 00:15:55.[=12= 的结果]
我曾尝试删除模数,以为我可以只对结果进行子字符串化,但这并没有改变 3597 结果,并且弄乱了在下面的代码下正确的多个结果。我还扩展了格式编号以包含更多数字,但这也不会改变结果。我也尝试过使用 floor($Duration - $hours div 60),但似乎没有用,或者我的格式不对。
我错过了什么?我看不出 3597/60 怎么等于 60,尤其是当我取模数时。
<xsl:template name="calculatedDuration">
<xsl:param name="Duration"/>
<xsl:choose>
<xsl:when test="$Duration >= 3600">
<xsl:value-of select="concat(format-number($Duration div 3600, '00'), ':')"/>
</xsl:when>
<xsl:otherwise>00:</xsl:otherwise>
</xsl:choose>
<xsl:value-of select="format-number($Duration div 60 mod 60, '00')"/>
<xsl:value-of select="concat(':', format-number($Duration mod 60, '00'))"/>
</xsl:template>
这是因为 format-number
进行舍入,而不是截断。 format-number(59.97, '00')
的值为 60,而不是 59。因此请改用 format-number(floor($Duration div 60) mod 60, '00')
。