"The scale must be a positive integer or zero");
}
BigDecimal b1 = new BigDecimal(v1);
BigDecimal b2 = new BigDecimal(v2);
return b1.divide(b2, scale, round_mode).toString();
}
public static double round(double v, int scale)
{
return round(v, scale, BigDecimal.ROUND_HALF_EVEN);
}
public static double round(double v, int scale, int round_mode)
{
if (scale < 0)
{
throw new IllegalArgumentException(
"The scale must be a positive integer or zero");
}
BigDecimal b = new BigDecimal(Double.toString(v));
return b.setScale(scale, round_mode).doubleva lue();
}
public static String round(String v, int scale)
{
return round(v, scale, BigDecimal.ROUND_HALF_EVEN);
}
public static String round(String v, int scale, int round_mode)
{
if (scale < 0)
{
throw new IllegalArgumentException(
"The scale must be a positive integer or zero");
}
BigDecimal b = new BigDecimal(v);
return b.setScale(scale, round_mode).toString();
}
public static void main(String[] args) {
System.out.println(2.21 - 2);
System.out.println(7 * 0.8);
System.out.println(subtract(312.21, 312));
System.out.println(multiply(7, 0.8));
}
}