33 #define FB_MAXFIXLEN 19
55 char *pszFracStart, *pszFracEnd;
58 double dblFrac = modf( number, &dblFix );
59 long long llFix = (
long long) dblFix;
60 ssize_t len_fix, len_frac;
67 len_frac = sprintf( pachFracPart,
"%.*f", precision, dblFrac );
71 pszFracStart = pachFracPart;
72 if( *pszFracStart==
'-' )
75 pszFracEnd = pachFracPart + len_frac;
76 while( pszFracEnd!=pszFracStart ) {
78 if( *pszFracEnd!=
'0' ) {
79 if( *pszFracEnd!=chDecimalPoint ) {
88 len_frac = pszFracEnd - pszFracStart;
89 memmove( pachFracPart, pszFracStart, len_frac );
90 pachFracPart[len_frac] = 0;
93 if( llFix==0 && number < 0.0 ) {
97 }
else if( llFix==0 && number > 0.0 ) {
105 }
else if( llFix > 0 ) {
110 len_fix = sprintf( pachFixPart,
"%" FB_LL_FMTMOD "d", llFix );
113 if( pcchLenFix!=
NULL )
114 *pcchLenFix = len_fix;
115 if( pcchLenFrac!=
NULL )
116 *pcchLenFrac = len_frac;
126 char thousands_separator
129 char FixPart[128], FracPart[128], chSign;
130 ssize_t LenFix, LenFrac, LenSign, LenDecPoint, LenTotal;
140 LenSign = ( ( chSign==
'-' ) ? 1 : 0 );
141 LenDecPoint = ( ( LenFrac!=0 ) ? 1 : 0 );
142 LenTotal = LenSign + LenFix + LenDecPoint + LenFrac;
149 dst->
data[0] = chSign;
152 if( LenDecPoint!=0 ) {
153 dst->
data[LenSign + LenFix] = decimal_point;
158 dst->
data[LenTotal] = 0;
172 double fix, frac = modf( value, &fix );
180 long long int intfrac = (
long long int)(frac * 1.E+15);
181 if( intfrac > (
long long int)(5.E+14) )
182 value = ceil( value );
183 else if( intfrac < -(
long long int)(5.E+14) )
184 value = floor( value );
194 double fracfrac = modf( frac * p10, &frac );
197 long long int intfrac = (
long long int)(fracfrac * (1.E+15 / p10) );
199 if( intfrac > (
long long int)(5.E+14 / p10) )
201 else if( intfrac < -(
long long int)(5.E+14 / p10) )
239 char FixPart[128], FracPart[128], ExpPart[128], chSign = 0;
240 ssize_t LenFix, LenFrac, LenExp = 0, IndexFix, IndexFrac, IndexExp = 0;
241 ssize_t ExpValue, ExpAdjust = 0, NumSkipFix = 0, NumSkipExp = 0;
245 int do_output = dst!=
NULL;
268 ExpValue = (int)floor( log10( fabs( value ) ) ) + 1;
307 value *= pow( 10.0, -ExpValue );
309 LenExp = sprintf( ExpPart,
"%d", (
int)ExpValue );
312 IndexExp = ExpAdjust = 1;
314 IndexExp = ExpAdjust = 0;
316 NumSkipExp = pInfo->
exp_digits - ( LenExp - ExpAdjust );
319 else if( ExpValue < 0 )
347 value *= pow( 10.0, -ExpValue );
353 value =
hRound( value, pInfo );
367 for( i = 0; i < ExpValue; i++ )
368 FixPart[LenFix+i] =
'0';
372 FixPart[LenFix] =
'\0';
387 IndexFix = IndexFrac = 0;
388 for( i=0; i!=mask_length; ++i ) {
389 const char *pszAdd = mask + i;
390 char *pszAddFree =
NULL;
392 char chCurrent = *pszAdd;
400 }
else if( do_exp ) {
403 switch( chCurrent ) {
429 }
else if( do_string ) {
430 if( chCurrent==
'"' ) {
432 }
else if( !do_output ) {
439 switch (chCurrent ) {
443 if( !pInfo->
has_sign && !did_sign ) {
452 }
else if( NumSkipFix < 0 ) {
454 pszAdd = FixPart + IndexFix;
456 int remaining = LenFix - IndexFix;
457 if( (remaining % 3)==0 ) {
458 if( did_thousandsep ) {
459 did_thousandsep =
FALSE;
462 did_thousandsep =
TRUE;
463 pszAdd = &chThousandsSep;
467 LenAdd = remaining % 3;
470 LenAdd = -NumSkipFix;
473 if( !did_thousandsep ) {
475 NumSkipFix += LenAdd;
485 switch( chCurrent ) {
532 switch( chCurrent ) {
555 if( last_was_comma ) {
567 pszAdd = &chDecimalPoint;
575 if( last_was_comma ) {
579 last_was_comma =
TRUE;
585 if( last_was_comma ) {
588 last_was_comma =
TRUE;
600 }
else if( did_exp ) {
605 if( chCurrent==
'#' ) {
616 if( IndexFrac!=LenFrac ) {
617 pszAdd = FracPart + IndexFrac++;
619 }
else if( chCurrent==
'0' ) {
622 }
else if( did_exp ) {
623 if( NumSkipExp > 0 ) {
624 if( chCurrent==
'0' ) {
628 }
else if( IndexExp!=LenExp ) {
629 pszAdd = ExpPart + IndexExp++;
631 && ( IndexExp!=LenExp ) )
642 int remaining = LenFix - IndexFix + NumSkipFix;
643 if( (remaining % 3)==0 ) {
644 if( did_thousandsep ) {
645 did_thousandsep =
FALSE;
647 if( NumSkipFix==0 && IndexFix!=0 ) {
648 did_thousandsep =
TRUE;
649 pszAdd = &chThousandsSep;
664 if( IndexFix!=LenFix ) {
665 pszAdd = FixPart + IndexFix++;
667 }
else if( chCurrent==
'0' ) {
727 }
else if( !did_sign ) {
756 int old_did_hour = did_hour;
758 while( mask[i+count]==chCurrent )
761 if( chCurrent==
'm' ) {
762 if( count>2 || !old_did_hour ) {
766 if( chCurrent==
't' && count==5 ) {
776 pszAddFree = strdup( tmp->
data );
781 }
else if( chCurrent==
't' && (count==1 || count==2) ) {
796 }
else if( chCurrent==
'd' && count==5 ) {
806 pszAddFree = strdup( tmp->
data );
811 }
else if( chCurrent==
'd' && count==1 ) {
817 LenAdd = sprintf( ((pszAdd = FixPart), FixPart),
822 }
else if( chCurrent==
'd' && count==2 ) {
827 LenAdd = sprintf( ((pszAdd = FixPart), FixPart),
832 }
else if( chCurrent==
'd' && (count==3 || count==4) ) {
839 pszAddFree = strdup( tmp->
data );
844 }
else if( (chCurrent==
'm' || chCurrent ==
'n') && count==1 ) {
850 LenAdd = sprintf( ((pszAdd = FixPart), FixPart),
855 }
else if( (chCurrent==
'm' || chCurrent ==
'n') && count==2 ) {
860 LenAdd = sprintf( ((pszAdd = FixPart), FixPart),
865 }
else if( (chCurrent==
'h' || chCurrent==
'H') && count==1 ) {
872 if( pInfo->
has_ampm && chCurrent==
'h') {
875 }
else if( hour==0 ) {
879 LenAdd = sprintf( ((pszAdd = FixPart), FixPart),
885 }
else if( (chCurrent==
'h' || chCurrent==
'H') && count==2 ) {
891 if( pInfo->
has_ampm && chCurrent==
'h' ) {
894 }
else if( hour==0 ) {
898 LenAdd = sprintf( ((pszAdd = FixPart), FixPart),
904 }
else if( chCurrent==
's' && count==1 ) {
910 LenAdd = sprintf( ((pszAdd = FixPart), FixPart),
915 }
else if( chCurrent==
's' && count==2 ) {
920 LenAdd = sprintf( ((pszAdd = FixPart), FixPart),
925 }
else if( chCurrent==
'M' && count==1 ) {
931 LenAdd = sprintf( ((pszAdd = FixPart), FixPart),
936 }
else if( chCurrent==
'M' && count==2 ) {
941 LenAdd = sprintf( ((pszAdd = FixPart), FixPart),
946 }
else if( chCurrent==
'M' && (count==3 || count==4) ) {
953 pszAddFree = strdup( tmp->
data );
958 }
else if( chCurrent==
'y' && count<3 ) {
963 LenAdd = sprintf( ((pszAdd = FixPart), FixPart),
968 }
else if( chCurrent==
'y' && count==4 ) {
973 LenAdd = sprintf( ((pszAdd = FixPart), FixPart),
1010 pszAdd = &chTimeSep;
1019 if( (strncasecmp( mask+i,
"AM/PM", 5 )==0)
1020 || (strncasecmp( mask+i,
"A/P", 3 )==0) )
1031 int ampm_small = mask[i+1]==
'/';
1032 LenAdd = ( ampm_small ? 1 : 2 );
1033 if(
fb_Hour( value ) >= 12 ) {
1034 pszAdd = mask + i + LenAdd + 1;
1040 i += ((mask[i+1]==
'/') ? 2 : 4);
1069 if( last_was_comma && (chCurrent!=
',' || i==(mask_length-1)) ) {
1070 if( !do_output && !was_k_div ) {
1073 last_was_comma =
FALSE;
1080 if( pszAddFree!=
NULL )
1081 pszAdd = pszAddFree;
1083 LenAdd = strlen( pszAdd );
1088 if( pszAddFree!=
NULL ) {
1126 const char *pszIntlResult;
1127 char chDecimalPoint, chThousandsSep, chDateSep, chTimeSep;
1133 chDecimalPoint = (( pszIntlResult==
NULL ) ?
'.' : *pszIntlResult );
1135 chThousandsSep = (( pszIntlResult==
NULL ) ?
',' : *pszIntlResult );
1137 chDateSep = (( pszIntlResult==
NULL ) ?
'/' : *pszIntlResult );
1139 chTimeSep = (( pszIntlResult==
NULL ) ?
':' : *pszIntlResult );
1142 if( chDecimalPoint==0 )
1143 chDecimalPoint =
'.';
1144 if( chThousandsSep==0 )
1145 chThousandsSep =
',';
1149 if( mask ==
NULL || mask_length==0 )
1161 chThousandsSep, chDecimalPoint,
1162 chDateSep, chTimeSep ) )
1176 chThousandsSep, chDecimalPoint,
1177 chDateSep, chTimeSep );