arithmetic

두 개의 수(왼쪽에 있는 수와 오른쪽에 있는 수)에 대해 산술 계산을 수행하고 선택적으로 결과를 지정된 소수점 이하 자릿수로 반올림합니다.

지원되는 조작은 다음과 같습니다.

반올림해야 하는 경우 다음을 지정해야 합니다.

경고: 나누기 조작의 경우 일반적으로 반올림 모드와 소수점 이하 자릿수를 제공해야 합니다. 제공하지 않는 않고 런타임 시 정확한 결과를 계산할 수 없는 경우 런타임 오류가 발생합니다.

규칙 세트에서 지정된 반올림이 지정되지 않은 나누기 조작을 발견한 경우 CER 규칙 세트 유효성 검증기가 경고를 발행합니다.

<?xml version="1.0" encoding="UTF-8"?>
<RuleSet name="Example_arithmetic"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:noNamespaceSchemaLocation=
"http://www.curamsoftware.com/CreoleRulesSchema.xsd">
  <Class name="ArithmeticExampleRuleClass">

    <!-- 3 + 2 = 5 -->
    <Attribute name="addANumberToAnother">
      <type>
        <javaclass name="Number"/>
      </type>
      <derivation>
        <arithmetic operation="+">
          <Number value="3"/>
          <Number value="2"/>
        </arithmetic>
      </derivation>
    </Attribute>

    <!-- 3 - 2 = 1 -->
    <Attribute name="subtractANumberFromAnother">
      <type>
        <javaclass name="Number"/>
      </type>
      <derivation>
        <arithmetic operation="-">
          <Number value="3"/>
          <Number value="2"/>
        </arithmetic>
      </derivation>
    </Attribute>

    <!-- 3 * 2 = 6 -->
    <Attribute name="multiplyANumberByAnother">
      <type>
        <javaclass name="Number"/>
      </type>
      <derivation>
        <arithmetic operation="*">
          <Number value="3"/>
          <Number value="2"/>
        </arithmetic>
      </derivation>
    </Attribute>

    <!-- 3 / 2 = 1.5 -->
    <!-- 2로 나누기를 하므로
         반올림을 하지 않아도 됩니다.
         그러나 CER 규칙 세트 유효성 검증기가
         여전히 경고를 발행합니다. -->
    <Attribute name="divideANumbersByAnother">
      <type>
        <javaclass name="Number"/>
      </type>
      <derivation>
        <arithmetic operation="/">
          <Number value="3"/>
          <Number value="2"/>
        </arithmetic>
      </derivation>
    </Attribute>

    <!-- (3 + 2) * 4 = 20 -->
    <Attribute name="chainedArithmetic">
      <type>
        <javaclass name="Number"/>
      </type>
      <derivation>
        <arithmetic operation="*">
          <arithmetic operation="+">
            <Number value="3"/>
            <Number value="2"/>
          </arithmetic>
          <Number value="4"/>
        </arithmetic>
      </derivation>
    </Attribute>

    <!-- 1.23 + 3.45 = 4.68,
         = 4.7(소수점 이하 1자리의 근사치로 반올림하는 경우)-->
    <Attribute name="roundedAddition">
      <type>
        <javaclass name="Number"/>
      </type>
      <derivation>
        <arithmetic decimalPlaces="1" operation="+"
          rounding="half_up">
          <Number value="1.23"/>
          <Number value="3.45"/>
        </arithmetic>
      </derivation>
    </Attribute>

    <!-- 2 / 3, = 0.667(소수점 이하 3자리까지) -->
    <!-- 반올림이 지정되지 않은 경우
         런타임 오류가 발생함 -->
    <Attribute name="roundedDivision">
      <type>
        <javaclass name="Number"/>
      </type>
      <derivation>
        <arithmetic decimalPlaces="3" operation="/"
          rounding="half_up">
          <Number value="2"/>
          <Number value="3"/>
        </arithmetic>
      </derivation>
    </Attribute>

  </Class>

</RuleSet>