68 int n1, ne, nf, digitsRightOfPeriod_f, exponent;
69 char Str_e[512], Str_f[512], *Str_r = Str_e, Fmt[32], *e1, *e2;
70 const char *
sign =
"";
75 sprintf( Fmt,
"%%%sf", sign );
76 sprintf( Str_e, Fmt,
value );
77 return( strdup( Str_e ) );
81 if( significantDigits < 0 ) significantDigits = 0;
82 if( significantDigits > 24 ) significantDigits = 24;
84 sprintf( Fmt,
"%%%s.%de", sign, significantDigits );
85 sprintf( Str_e, Fmt,
value );
87 e1 = strchr( Str_e,
'e' );
88 if( significantDigits == 0 ) {
89 if( *(e1 - 1) !=
'.' ) {
94 for( ; e2 != e1; e2--, e3-- ) *e3 = *e2;
99 n1 = (
int) strlen( Str_e ) - 1;
102 if( !( flags & nf_floatToShortestString_keepPeriod ) )
if( Str_e[n1] ==
'.' ) n1--;
107 exponent = (
int) strtol( e1, &e2, 10 );
108 if( exponent != 0 ) {
109 for( e1 = Str_e; *e1 != 0; e1++ ) ;
110 sprintf( e1,
"e%d", exponent );
112 digitsRightOfPeriod_f = significantDigits - exponent;
113 if( ( digitsRightOfPeriod_f > 25 ) || ( exponent > 50 ) )
return( strdup( Str_r ) );
114 if( digitsRightOfPeriod_f < 0 ) digitsRightOfPeriod_f = 0;
116 sprintf( Fmt,
"%%%s.%df", sign, digitsRightOfPeriod_f );
117 sprintf( Str_f, Fmt,
value );
119 ne = (
int) strlen( Str_e );
120 nf = (
int) strlen( Str_f );
121 if( strchr( Str_f,
'.' ) != NULL ) {
122 if( flags & nf_floatToShortestString_trimZeros )
while( Str_f[nf-1] ==
'0' ) nf--;
123 if( Str_f[nf-1] ==
'.' ) {
124 if( !( flags & nf_floatToShortestString_keepPeriod ) ) nf--;
127 if( flags & nf_floatToShortestString_keepPeriod ) {
134 if( ( nf + favorEFormBy ) < ne ) Str_r = Str_f;
136 return( strdup( Str_r ) );
#define nf_floatToShortestString_trimZeros
const XML_Char int const XML_Char * value
typedef int(XMLCALL *XML_NotStandaloneHandler)(void *userData)
#define nf_floatToShortestString_includeSign
#define nf_floatToShortestString_keepPeriod