round number to 2 decimal places

rounding, tcl

Solution

expr {double(round(100*$total_rate))/100}

example

% set total_rate 1.5678
1.5678
% expr {double(round(100*$total_rate))/100}
1.57
% set total_rate 1.4321
1.4321
% expr {double(round(100*$total_rate))/100}
1.43

Problem

I need to round a number to two decimal places. Right now the following rounds to the nearest integer I guess ``` puts [expr {round($total_rate)}] ``` If I do something like below it does not work. Is there another way around? ``` puts [expr {round($total_rate,2)}] ```

Original source