|
2026-01-15
| ||
| 08:18 | • Closed ticket [bd71dd3305]: round() function with precision argument rounding aw... artifact: 7b5e0a36fd user: anonymous | |
|
2026-01-12
| ||
| 04:27 | • Ticket [bd71dd3305]: 3 changes artifact: 00ca79a183 user: cdubois | |
|
2025-12-12
| ||
| 17:22 | • Ticket [bd71dd3305]: 3 changes artifact: 77b4939d87 user: anonymous | |
| 15:31 | • Ticket [bd71dd3305]: 3 changes artifact: 6bdfda6509 user: anonymous | |
|
2025-11-27
| ||
| 09:40 | • Ticket [bd71dd3305]: 3 changes artifact: f3707b9826 user: anonymous | |
| 09:15 | • Ticket [bd71dd3305]: 3 changes artifact: 0c1ebe7dab user: anonymous | |
|
2025-11-26
| ||
| 14:38 | • Ticket [bd71dd3305]: 3 changes artifact: dfb17304db user: dkf | |
|
2025-11-21
| ||
| 15:22 | • New ticket [bd71dd3305]. artifact: d1135eb01c user: anonymous | |
round() function with precision argument rounding away from zero
Closedbd71dd33055d27d7fc8f075412359822195c3cd9Created 1 year agoUpdated 322 days ago
Descriptionplain2025-11-21 15:22:39
When doing arithmetic operations on numbers as, for example, multiply somme amount by a rate, we need the result to be rounded away from zero to a desired precision (wich excludes usage of "format" command as it simply drops unwanted decimals) Thank you Jean-Marie
dkfmarkdown2025-11-26 14:38:10
It would definitely be good to have something that gives more control over rounding modes. There are many such methods.
Might be better as a command.
anonymousplain2025-11-27 09:15:36
Yes this subject is a wide one ... For a general purpose langage, the lack of the most common rounding method of fp numbers is a surprise (compared to the range of mathematical functions offered, on the other hand, in ::tcl::mathfunc). I share your point of vue : a new design should provide sufficient flexibility to maximize its usefullness. However, I'm not sure about the effective need of other methods than "away from zero" or "toward zero" (in Tcl/Tk projects). A possible supplemental argument in favour of a function against a command is that with a sole suplementary precision argument to the existing round() function, some flexibility can be obtained in giving the choice between two methods based on the positive or negative sign of the precision argument (a way wich seems not too counter intuitive to me, convenient, but yes something unusal) Thenk you Jean-Marie
anonymousplain2025-11-27 09:40:21
Sorry, I missed an obvious point in this discussion of a function against a command : the practical convenience in writing, and the low as possible processing overhead Thank you Jean-Marie
anonymousplain2025-12-12 15:31:11
I just realized that Python' round() method with precision argument choosed "half to even" rounding method. As I didn't thought about aggregates of fp numbers (a bad idea, rounded or not), I want to precise that the need expressed in this ticket is about rounding fp numbers used in isolation (I should have written this in the title of this ticket). However, if "half to even" method is prefered by the Development Team for some reason, while producing a result less immediately intuitive for isolated fp numbers, it is netherthess allso fine on our side. Thank you Jean-Marie
anonymousplain2025-12-12 17:22:44
Shame on me : dkf you are right, a command is the solution Thank you Jean-Marie
cduboisplain2026-01-12 04:27:04
Thanks for the clarification, and +1 to dkf’s point: if Tcl ever grows first-class support for selectable rounding modes, a command (or small namespace) is probably the right shape.
For the immediate need of rounding to a given number of decimal places, [format] is often sufficient for producing a rounded decimal representation, e.g.:
set s [format "%.2f" $x] ;# rounded string
set y [expr {double($s)}] ;# numeric value again (if needed)
If a specific tie-breaking rule is required (e.g. “ties away from zero”), it may be better handled by a small helper at the script level, and a broader “multiple rounding modes” design can be discussed separately as its own RFE/TIP.
Given the reporter’s follow-up, this ticket may be closable as “documentation/workaround provided”, leaving any more general rounding-mode support for a dedicated proposal.
anonymousplain2026-01-15 08:18:07
Aggreed : my mistake Closing this ticket Jean-Marie
Log in (anonymous is fine) to add a comment.