Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 10th, 2008, 10:34 AM
Registered User
 
Join Date: Oct 2008
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Rounding to the nearest multiple of a number

Is it possible to round to the nearest multiple of a number in XSLT? For example, I have a variable with a value of 68, and I want to round it to the nearest multiple of 25. The resulting value should be 75. The closest thing I can find is round-half-even(), but that doesn't quite do what I want, since it only rounds to multiples of 10, from what I understand.

 
Old October 10th, 2008, 10:49 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

More correctly, round-half-to-even() can round to a multiple of 0.001, 0.01, 0.1, 1, 10, 100, 1000 etc.

Does it work to multiply by 4, round to a multiple of 100, then divide by 4?

Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer's Reference
 
Old October 10th, 2008, 11:08 AM
Registered User
 
Join Date: Oct 2008
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by mhkay
 More correctly, round-half-to-even() can round to a multiple of 0.001, 0.01, 0.1, 1, 10, 100, 1000 etc.

Does it work to multiply by 4, round to a multiple of 100, then divide by 4?

Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer's Reference
Ah thank you. I suspected it was right in front of me.






Similar Threads
Thread Thread Starter Forum Replies Last Post
Number(20,2) Rounding off Problem saravananedu Oracle 1 October 8th, 2005 11:10 PM
Rounding kilika SQL Server 2000 4 June 1st, 2005 03:36 PM
Calculating number of days between multiple dates Vann Access 4 December 3rd, 2004 08:26 PM
Multiple XML files matched with common Number Id gurbani XSLT 3 June 23rd, 2004 05:58 AM
Rounding in C# cjo ASP.NET 1.0 and 1.1 Basics 3 November 3rd, 2003 04:12 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.