/ Published in: TCL
Expand |
Embed | Plain Text
proc _round {num index} { # Procedure to round numerical results to any decimal or whole number. # The decimal or whole number digit is indicated using an index. # Index 0 is the nearest integer. # Decimals are indicated by positive indicies: 1 or the first decimal, 2 for the second, etc. # Whole numbers are indicated by negative indicies: -1 for nearest 10th, -2 for the nearest hundreth, etc. # Example: # # Number: 9 9 9 . 9 9 9 # Index: -2 -1 0 1 2 3 # # Index 1 = 0.x # Index 2 = 0.0x # Index 3 = 0.00x # Index 0 = x # Index -1 = x0 # Index -2 = x00 # Index -3 = x000 set multiplier [expr pow(10,$index)] return [expr (round(($num * $multiplier)) / $multiplier)] }
You need to login to post a comment.
