Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

round number to 2 decimal places

Tags:

rounding

tcl

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)}]
like image 295
Micheal Avatar asked Apr 18 '12 15:04

Micheal


1 Answers

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
like image 166
glenn jackman Avatar answered Nov 02 '22 23:11

glenn jackman