Loriot Posted August 22, 2006 Share Posted August 22, 2006 Hi all,I have a little wrong working transformation and would appriciate some help from you: For a value coming in Milliseconds I try to transform it to minutes:seconds.milliseconds with the following call-template: <xsl:template name="processLength"> <xsl:param name="milliseconds"/> <xsl:variable name="minutes" select=" ($milliseconds div 60000)"/> <xsl:variable name="seconds" select="($milliseconds mod (1000*60)) div 1000"/> <xsl:value-of select="concat(format-number($minutes, '00'), ':', format-number($seconds, '00', 'european'))"/></xsl:template> The transformation looks nice, just the values do not fit all the time. If I have 1min29sec it is allright. If I have 1min44sec I get 2min out here. So it seems to round up from 0,5. How can I make that work correctly?Hope to hear from you soon\Loriot Link to comment Share on other sites More sharing options...
Loriot Posted August 22, 2006 Author Share Posted August 22, 2006 hihi, now I found out on my own. The solution is the floor function.So now I got working code with that:</xsl:template><xsl:decimal-format name="european" decimal-separator=","/><xsl:template name="processLength"> <xsl:param name="milliseconds"/> <xsl:variable name="minutes" select=" floor($milliseconds div 60000)"/> <xsl:variable name="seconds" select="($milliseconds mod (1000*60)) div 1000"/> <xsl:value-of select="concat(format-number($minutes, '00'), ':', format-number($seconds, '00', 'european'))"/></xsl:template> Link to comment Share on other sites More sharing options...
boen_robot Posted August 22, 2006 Share Posted August 22, 2006 The floor() function can be used to remove roundings. Or to be more precise: It returns the largest integer that is not greater than the number argument.Where should you place it is another question though...either <xsl:variable name="minutes" select="floor($milliseconds div 60000)"/> or <xsl:variable name="seconds" select="floor(($milliseconds mod (1000*60)) div 1000)"/> or maybe both.[edit]Funny. When I posted my post, your second one wasn't there.[/edit] Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now