Artifacts Associated With Ticket 3564821fffffffff
Ticket change [5a4e18d522] (rid 118121) by jmcuaz on 2012-09-04 21:22:46:
- assignee initialized to: "dgp"
- cmimetype initialized to: "text/plain"
- comment initialized to:
When dealing with floating point numbers, there is no easy way in tcl to do something like "round( 2.125 , 2 )" with an expected return of 2.13 For the choice of upward/downward rounding (i.e. toward inf+ or inf-) and to disambiguate the semantic of rounding on negatives fp numbers, maybe two separate functions would be good : something like roundup(x,y) -> toward inf+ rounddown(x,y) -> toward inf- Regards Jean-Marie Cuaz
- foundin initialized to: "None"
- is_private initialized to: "0"
- priority initialized to: "5 Medium"
- resolution initialized to: "None"
- status initialized to: "Open"
- submitter initialized to: "jmcuaz"
- subsystem initialized to: "48. Number Handling"
- title initialized to:
math rounding function with arbitrary decimal precision
- type initialized to: "RFE"
Ticket change [2a16c826c2] (rid 118493) by sebres on 2012-09-05 16:16:48:
- icomment:
Why can you not use "format" like this? % format %.2f 2.125 2.13 And if you really need a mathematical function, you can simple create it self, something like this: % proc ::tcl::mathfunc::roundup {n e} {double [format %.${e}f $n]} % puts [expr roundup( 2.555, 2 )] 2.56 - login: "sebres"
- mimetype: "text/plain"
- username: "sebres"
- icomment:
Ticket change [ec616519e0] (rid 103703) by jmcuaz on 2012-09-05 17:21:19:
- icomment:
You are right. format f does an arithmetical rounding and not the simple truncation I understood when reading the doc : <quote> For e, E, and f conversions it specifies the number of digits to appear to the right of the decimal point. <end of quote>. Sorry for the nuisance and thanks for the clarification Regards Jean-Marie
- login: "jmcuaz"
- mimetype: "text/plain"
- username: "jmcuaz"
- icomment:
Ticket change [a853cfee37] (rid 98965) by sebres on 2012-09-05 17:44:50:
- closedate changed to: "2012-09-05T10:44:50"
- closer changed to: "sebres"
- resolution changed to: "Accepted"
- status changed to: "Closed"