/*
**
** Licensed Materials - Property of IBM 1.4
**
** (C) COPYRIGHT International Business Machines Corp. 1995, 1999
** All Rights Reserved.
**
** US Government Users Restricted Rights - Use, duplication or
** disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
**
** For more information about these samples see the README file.
**
** For more information on programming in CLI see the:
** - "Building CLI Applications" section of the Application Building Guide, and the
** - CLI Guide and Reference.
**
** For more information on the SQL language see the SQL Reference.
**
*/
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <sqludf.h>
void SQL_API_FN price( SQLUDF_CHAR * uprice,
SQLUDF_CHAR * units,
SQLUDF_CHAR * num_units,
SQLUDF_CHAR * price,
SQLUDF_SMALLINT * upriceNullInd,
SQLUDF_SMALLINT * unitsNullInd,
SQLUDF_SMALLINT * num_unitsNullInd,
SQLUDF_SMALLINT * priceNullInd,
SQLUDF_TRAIL_ARGS
) {
double new_price ;
int switch_ch ;
switch_ch = ( int ) units[ 0 ] ;
switch ( switch_ch ) {
case 'k':
case 'l':
case 'm':
new_price = ceil( ( ceil( atof( num_units ) * 100 ) * .01 ) * atof( uprice ) * 100 ) * .01 ;
break ;
default:
new_price = ceil( atof( num_units ) * atof( uprice ) * 100 ) * .01 ;
break ;
}
sprintf( price, "%12.2lf", new_price ) ;
} /* end of UDF : price */