Example #1
0
 /** Convert rational to (rounded) integer, after multiplying by 10**k. */
 public static IntNum toScaledInt(RatNum r, int k)
 {
     if (k != 0)
     {
         IntNum power = IntNum.power(IntNum.ten(), k < 0 ? -k : k);
         IntNum num   = r.numerator();
         IntNum den   = r.denominator();
         if (k >= 0)
         {
             num = IntNum.times(num, power);
         }
         else
         {
             den = IntNum.times(den, power);
         }
         r = RatNum.make(num, den);
     }
     return(r.toExactInt(ROUND));
 }