22 #include "my_global.h"
28 #include "decimal_utils.hpp"
30 int decimal_str2bin(
const char *str,
int str_len,
32 void *bin,
int bin_len)
36 decimal_digit_t digits[9];
37 char *end = (
char *) str + str_len;
41 if(prec < 1)
return E_DEC_BAD_PREC;
42 if((scale < 0) || (scale > prec))
return E_DEC_BAD_SCALE;
44 if(decimal_bin_size(prec, scale) > bin_len)
50 retval = string2decimal(str, &dec, &end);
51 if(retval != E_DEC_OK)
return retval;
53 return decimal2bin(&dec, (
unsigned char *) bin, prec, scale);
56 int decimal_bin2str(
const void *bin,
int bin_len,
58 char *str,
int str_len)
62 decimal_digit_t digits[9];
67 if(prec < 1)
return E_DEC_BAD_PREC;
68 if((scale < 0) || (scale > prec))
return E_DEC_BAD_SCALE;
74 retval = bin2decimal((
const uchar *) bin, &dec, prec, scale);
75 if(retval != E_DEC_OK)
return retval;
77 to_len = decimal_string_size(&dec);
78 if(to_len > str_len)
return E_DEC_OOM;
80 return decimal2string(&dec, str, &to_len, 0, 0, 0);