This was exactly what I was looking for but after playing with it a bit, I'd recommend 1 change. If the user passes the proc 1 digit, the returned value would be \d.**\d** which is great. But if the user doesn't pass digits or passes it as 0, the return will be \d.**0** which is inaccurate. So the enhancement would be:
proc round {number {digits 0}} {
if { $digits} {
return [expr {round(pow(10,$digits)*$number)/pow(10,$digits)}]
} else {
return [ int [expr {round(pow(10,$digits)*$number)/pow(10,$digits)}]]
}
}
Thanks for the snippet, helped a lot. |