summaryrefslogtreecommitdiff
path: root/ext/bcmath/libbcmath/src/num2str.c
diff options
context:
space:
mode:
Diffstat (limited to 'ext/bcmath/libbcmath/src/num2str.c')
-rw-r--r--ext/bcmath/libbcmath/src/num2str.c13
1 files changed, 8 insertions, 5 deletions
diff --git a/ext/bcmath/libbcmath/src/num2str.c b/ext/bcmath/libbcmath/src/num2str.c
index c72a924933..7316d32a14 100644
--- a/ext/bcmath/libbcmath/src/num2str.c
+++ b/ext/bcmath/libbcmath/src/num2str.c
@@ -41,8 +41,9 @@
/* Convert a numbers to a string. Base 10 only.*/
zend_string
-*bc_num2str (num)
+*bc_num2str_ex (num, scale)
bc_num num;
+ int scale;
{
zend_string *str;
char *sptr;
@@ -51,8 +52,8 @@ zend_string
/* Allocate the string memory. */
signch = ( num->n_sign == PLUS ? 0 : 1 ); /* Number of sign chars. */
- if (num->n_scale > 0)
- str = zend_string_alloc(num->n_len + num->n_scale + signch + 1, 0);
+ if (scale > 0)
+ str = zend_string_alloc(num->n_len + scale + signch + 1, 0);
else
str = zend_string_alloc(num->n_len + signch, 0);
if (str == NULL) bc_out_of_memory();
@@ -67,11 +68,13 @@ zend_string
*sptr++ = BCD_CHAR(*nptr++);
/* Now the fraction. */
- if (num->n_scale > 0)
+ if (scale > 0)
{
*sptr++ = '.';
- for (index=0; index<num->n_scale; index++)
+ for (index=0; index<scale && index<num->n_scale; index++)
*sptr++ = BCD_CHAR(*nptr++);
+ for (index = num->n_scale; index<scale; index++)
+ *sptr++ = BCD_CHAR(0);
}
/* Terminate the string and return it! */