function setScale() {
  var round;
  if (setScale.arguments.length == 2)
   {
    round = setScale.arguments[1];
   }
  else if (setScale.arguments.length == 1)
   {
    round = this.ROUND_UNNECESSARY;
   }
  else
   {
    throw "setScale(): " + setScale.arguments.length + " given; expected 1 or 2";
   }
  var scale = setScale.arguments[0];
  //--int ourscale;
  var ourscale;
  //--com.ibm.icu.math.BigDecimal res;
  var res;
  //--int padding=0;
  var padding=0;
  //--int newlen=0;
  var newlen=0;
  // at present this naughtily only checks the round value if it is
  // needed (used), for speed
  ourscale=this.scale();
  if (ourscale==scale)  // already correct scale
   if (this.form==MathContext.prototype.PLAIN)  // .. and form
    return this;
  res=this.clone(this); // need copy
  if (ourscale<=scale)
   { // simply zero-padding/changing form
    // if ourscale is 0 we may have lots of 0s to add
    if (ourscale==0)
     padding=res.exp+scale;
    else
     padding=scale-ourscale;
    res.mant=this.extend(res.mant,res.mant.length+padding);
    res.exp=-scale; // as requested
   }
  else
   {/* ourscale>scale: shortening, probably */
    if (scale<0)
     //--throw new java.lang.ArithmeticException("Negative scale:"+" "+scale);
     throw "setScale(): Negative scale: " + scale;
    // [round() will raise exception if invalid round]
    newlen=res.mant.length-((ourscale-scale)); // [<=0 is OK]
    res=res.round(newlen,round); // round to required length
    // This could have shifted left if round (say) 0.9->1[.0]
    // Repair if so by adding a zero and reducing exponent
    if (res.exp!=(-scale))
     {
      res.mant=this.extend(res.mant,res.mant.length+1);
      res.exp=res.exp-1;
     }
   }
  res.form=MathContext.prototype.PLAIN; // by definition
  return res;
  }
Returns a plain <code>BigDecimal</code> with a given scale.
<p>
If the given scale (which must be zero or positive) is the same as
or greater than the length of the decimal part (the scale) of this
<code>BigDecimal</code> then trailing zeros will be added to the
decimal part as necessary.
<p>
If the given scale is less than the length of the decimal part (the
scale) of this <code>BigDecimal</code> then trailing digits
will be removed, and the rounding mode given by the second
parameter is used to determine if the remaining digits are
affected by a carry.
In this case, an <code>IllegalArgumentException</code> is thrown if
<code>round</code> is not a valid rounding mode.
<p>
If <code>round</code> is <code>MathContext.ROUND_UNNECESSARY</code>,
an <code>ArithmeticException</code> is thrown if any discarded
digits are non-zero.

@param  scale The <code>int</code> specifying the scale of the
              resulting <code>BigDecimal</code>.
@param  round The <code>int</code> rounding mode to be used for
              the division (see the {@link MathContext} class).
@return       A plain <code>BigDecimal</code> with the given scale.
@throws IllegalArgumentException if <code>round</code> is not a
              valid rounding mode.
@throws ArithmeticException if <code>scale</code> is negative.
@throws ArithmeticException if <code>round</code> is
              <code>MathContext.ROUND_UNNECESSARY</code>, and
              reducing scale would discard non-zero digits.
@stable ICU 2.0