Number of digits after the comma : LUSENET : WebdesignII : One Thread


How do I limit the number of digits after the comma in tcl???? My average is geting too big!!!

Greetings, Nada

-- Nada Alzubeidi (, November 09, 2000



you can use the following procedure trunc2. The procedure expects a number as argument and returns the same number with only two decimals. Bug: the procedure does not handle the case 23.23a right as it returns 23.23 instead of returning an error. However, this is not important in this assignment.

proc trunc2 {tal} { if {[regsub {^([0-9]+\.?[0-9]?[0-9]?).*$} $tal {\1} res] == 0} { return "$tal is not a number" } else { return $res } }

-- Niels Hallenberg (, November 09, 2000.

Alternatively, you can use the format command as in
  %> format "%.0f" 4343.2323
  %> format "%.0f" 43
to convert a floating point value to an integer.

-- Martin Elsman (, November 09, 2000.

Moderation questions? read the FAQ