Forum archive 2000-2006

Mark Schmitt - Rounding Function

Mark Schmitt - Rounding Function

by Arnold Pizer -
Number of replies: 0
inactiveTopicRounding Function topic started 3/1/2002; 7:27:21 AM
last post 3/7/2002; 4:55:15 PM
userMark Schmitt - Rounding Function  blueArrow
3/1/2002; 7:27:21 AM (reads: 875, responses: 1)
I found that I like being able to ask for answers rounded to a specified place. While it's easy enough to code the rounding into the problem using the round function found in PGauxiliary, I decided to make life a little easier by adding the following function:
sub Round{  ## Rounds to $_[1] places after the decimal point.  If 
## $_[1] is not given, rounds to the nearest integer



if (@_ == 1) { $_[0] > 0 ? int $_[0] + 0.5 : int $_[0] - 0.5}
elsif (@_ == 2) { $_{0] > 0 ? Round($_[0]*10**$_[1])/10**$_[1] : Round($_[0]*10**$_[1])/10**$_[1]}
}



--Mark

<| Post or View Comments |>


userAndy Wildenberg - Re: Rounding Function  blueArrow
3/7/2002; 4:55:15 PM (reads: 1097, responses: 0)
Could you adapt that function so that it does a floor after n places instead? I assume you could just replace "trunc" with "floor" everywhere. I have a decimal to rational number question that always has issues with the last digit getting rounded which causes lots of troubles with students. i.e.

Show that 8.60886088608861 is a rational number.

Of course I know that I should write a fancy latex macro that does the overline notation in the right place, but one thing at a time.

<| Post or View Comments |>