]>
git.saurik.com Git - apple/icu.git/blob - icuSources/common/ustrfmt.c
2 **********************************************************************
3 * Copyright (C) 2001-2004, International Business Machines
4 * Corporation and others. All Rights Reserved.
5 **********************************************************************
12 U_CAPI
char* U_EXPORT2
13 uprv_dtostr(double value
, char *buffer
, int maximumDigits
,UBool fixedPoint
)
15 char *itrPtr
= buffer
+ 1; /* skip '-' or a number before the decimal */
18 sprintf(buffer
,"%f",value
);
20 /* Find the decimal point.
21 Some unusal machines use a comma when the system locale changes
23 while (isalnum(*itrPtr
)) {
28 /* truncate trailing zeros, except the one after '.' */
29 startPtr
= itrPtr
+ 1;
30 itrPtr
= uprv_strchr(startPtr
, 0);
31 while(--itrPtr
> startPtr
){
42 * Fills in a UChar* string with the radix-based representation of a
43 * uint32_t number padded with zeroes to minwidth. The result
44 * will be null terminated if there is room.
46 * @param buffer UChar buffer to receive result
47 * @param capacity capacity of buffer
48 * @param i the unsigned number to be formatted
49 * @param radix the radix from 2..36
50 * @param minwidth the minimum width. If the result is narrower than
51 * this, '0's will be added on the left. Must be <=
53 * @return the length of the result, not including any terminating
56 U_CAPI
int32_t U_EXPORT2
57 uprv_itou (UChar
* buffer
, int32_t capacity
,
58 uint32_t i
, uint32_t radix
, int32_t minwidth
)
66 digit
= (int)(i
% radix
);
67 buffer
[length
++]=(UChar
)(digit
<=9?(0x0030+digit
):(0x0030+digit
+7));
69 } while(i
&& length
<capacity
);
71 while (length
< minwidth
){
72 buffer
[length
++] = (UChar
) 0x0030;/*zero padding */
74 /* null terminate the buffer */
76 buffer
[length
] = (UChar
) 0x0000;
79 /* Reverses the string */
80 for (j
= 0; j
< (length
/ 2); j
++){
81 temp
= buffer
[(length
-1) - j
];
82 buffer
[(length
-1) - j
] = buffer
[j
];