The decmul() function

The decmul() function multiplies two decimal type values.

Syntax

mint decmul(n1, n2, product)
   dec_t *n1;
   dec_t *n2;
   dec_t *product;
n1
A pointer to the decimal structure of the first operand.
n2
A pointer to the decimal structure of the second operand.
product
A pointer to the decimal structure that contains the product of n1 times n2.

Usage

The product can be the same as either n1 or n2.

Return codes

0
The operation was successful.
-1200
The operation resulted in overflow.
-1201
The operation resulted in underflow.

Example

The decmul.ec file in the demo directory contains the following sample program.
/*
   * decmul.ec *

   This program multiplies two DECIMAL numbers and displays the result.
*/

#include <stdio.h>

EXEC SQL include decimal;

char string1[] = "80.2";
char string2[] = "6.0";
char result[41];

main()
{
    mint x;
    dec_t num1, num2, mpx;

    printf("DECMUL Sample ESQL Program running.\n\n");

    if (x = deccvasc(string1, strlen(string1), &num1))
      {
      printf("Error %d in converting string1 to DECIMAL\n", x);
      exit(1);
      }
    if (x = deccvasc(string2, strlen(string2), &num2))
      {
      printf("Error %d in converting string2 to DECIMAL\n", x);
      exit(1);
      }
   if (x = decmul(&num1, &num2, &mpx))
      {
      printf("Error %d in converting multiply\n", x);
      exit(1);
      }
    if (x = dectoasc(&mpx, result, sizeof(result), -1))
      {
      printf("Error %d in converting mpx to display string\n", x);
      exit(1);
      }
    result[40] = '\0';
    printf("\t%s * %s = %s\n", string1, string2, result);

    printf("\nDECMUL Sample Program over.\n\n");
    exit(0);
}

Output

DECMUL Sample ESQL Program running.

   80.2 * 6.0 = 481.2

DECMUL Sample Program over.