Project

General

Profile

decimal.java.diff

Hynek Cihlar, 04/26/2014 12:13 PM

Download (4.2 KB)

View differences:

src/com/goldencode/p2j/util/decimal.java 2014-04-26 16:07:25 +0000
597 597
    */
598 598
   public static void setPrecision(decimal[] list, int precision)
599 599
   {
600
      // TODO: in case of dynamic-extent vars, this needs to be saved somewhere
600
      setPrecision(list, precision, false);
601
   }
602
   
603
   /**
604
    * Sets the number of digits that will be maintained to the right of
605
    * the decimal point in each element of the given array.  All assignments
606
    * to the value of those elements will be rounded/truncated to this number 
607
    * of digits.  The value can range between 0 and 10 (inclusive).
608
    *
609
    * @param    precision
610
    *           The precision which must range between 0 and 10 (inclusive).
611
    */
612
   public static void setLazyPrecision(decimal[] list, int precision)
613
   {
614
      setPrecision(list, precision, true);
615
   }
616
   
617
   /**
618
    * Sets the number of digits that will be maintained to the right of
619
    * the decimal point in each element of the given array.  All assignments
620
    * to the value of those elements will be rounded/truncated to this number 
621
    * of digits.  The value can range between 0 and 10 (inclusive).
622
    *
623
    * @param    precision
624
    *           The precision which must range between 0 and 10 (inclusive).
625
    */
626
   private static void setPrecision(decimal[] list, int precision, boolean lazy)
627
   {
601 628
      if (precision < 0 || precision > MAX_SCALE)
602 629
      {
603 630
         throw new IllegalArgumentException("Invalid precision " + precision + ".");
......
605 632
      
606 633
      for (int i = 0; i < list.length; i++)
607 634
      {
608
         list[i].setPrecision(precision);
635
         list[i].setPrecision(precision, lazy);
636
      }
637
      
638
      // set the decimal precision, for lengths > 0 the precision is stored 
639
	  // in the array components
640
      if (list.length == 0)
641
      {
642
         ArrayAssigner.setDecimalPrecision(list, precision);
609 643
      }
610 644
   }
611 645
   
......
1187 1221
    */
1188 1222
   public void setPrecision(int precision)
1189 1223
   {
1224
      setPrecision(precision, false);
1225
   }
1226
   
1227
   /**
1228
    * Sets the number of digits that will be maintained to the right of
1229
    * the decimal point in this instance.  All assignments to the value of
1230
    * this instance will be rounded/truncated to this number of digits.  The
1231
    * value can range between 0 and 10 (inclusive).
1232
    * <p>
1233
    * This method is used to set the current value in a manner that does not
1234
    * schedule an automated reset to the prior value later. Thus, this method
1235
    * is suitable for the initial configuration of a new instance.  If a
1236
    * temporary precision change is needed, use 
1237
    * {@link #setTemporaryPrecision}.
1238
    *
1239
    * @param    precision
1240
    *           The precision for this instance which must range between 0
1241
    *           and 10 (inclusive).
1242
    */
1243
   public void setLazyPrecision(int precision)
1244
   {
1245
      setPrecision(precision, true);
1246
   }
1247
   
1248
   /**
1249
    * Sets the number of digits that will be maintained to the right of
1250
    * the decimal point in this instance.  All assignments to the value of
1251
    * this instance will be rounded/truncated to this number of digits.  The
1252
    * value can range between 0 and 10 (inclusive).
1253
    * <p>
1254
    * This method is used to set the current value in a manner that does not
1255
    * schedule an automated reset to the prior value later. Thus, this method
1256
    * is suitable for the initial configuration of a new instance.  If a
1257
    * temporary precision change is needed, use 
1258
    * {@link #setTemporaryPrecision}.
1259
    *
1260
    * @param    precision
1261
    *           The precision for this instance which must range between 0
1262
    *           and 10 (inclusive).
1263
    */
1264
   private void setPrecision(int precision, boolean lazy)
1265
   {
1190 1266
      if (precision < 0 || precision > MAX_SCALE)
1191 1267
      {
1192 1268
         throw new IllegalArgumentException("Invalid precision " +
......
1198 1274
      // match the legacy terminology.
1199 1275
      scale = precision;
1200 1276
      
1201
      if (!isUnknown())
1277
      if (!lazy && !isUnknown())
1202 1278
      {
1203 1279
         value = value.setScale(precision, BigDecimal.ROUND_HALF_UP);
1204 1280
      }