On Oct 14, 2004, at 8:19 AM, Eric Anderson wrote:

> This seems like such a basic question yet I can't really find the 
> answer anywhere in the docs (I'm probably looking in the wrong place).
>
> Anyway I need to compute a percentage and output it. The percentage 
> should be in the form 39.45% (i.e. round to the nearest two decimal 
> places).

You're looking for sprintf():

sprintf "%.2f", 39.456789		# => 39.46

The ri docs for sprintf() will explain the format string options.

It also has a cousin, printf() that can used as the data is sent to 
some IO object.

Finally, the String class allows a shortcut:

"%.2f" % 39.456789				# => 39.46

Hope that helps.

James Edward Gray II